Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2003, 09:53 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP .NET code using C# problem !!

Hi,

   I got the following code:


<html>
<head>
  <title>Holiday page</title>
</head>
<body>
  <form action="holidayresponse.aspx" method="post">
    <h1>Feiertag Holidays</h1>
    Please enter your details here.
    <br /><br />
    Name:<asp:textbox id="FullName" runat="server" />
    <br /><br />
    Address:<asp:textbox id="Address" rows="5" textmode="multiline" runat="server" />
    <br /><br />
    ************ -
    <asp:radiobuttonlist id="************" runat="server">
      <asp:listitem value="Male" />
      <asp:listitem value="Female" />
    </asp:radiobuttonlist>
    Please select the destination you would like details on:
    <asp:dropdownlist id="Destination" runat="server">
      <asp:listitem value="Madrid" />
      <asp:listitem value="Barcelona" />
      <asp:listitem value="Lisbon" />
      <asp:listitem value="Oslo" />
      <asp:listitem value="Prague" />
    </asp:dropdownlist>
    <br /><br />
      <input type="Submit">
    <input type="Reset">
  </form>
</body>
</html>


and I got the following error message:


Control 'FullName' of type 'TextBox' must be placed inside a form tag with runat=server


I got this code from Wrox's Beginnging ASP .NET using C# on chp3 where the filename is holidaypage.aspx.

pls......help...........
 
Old July 9th, 2003, 10:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

 
Quote:
quote:Control 'FullName' of type 'TextBox' must be placed inside a form tag with runat=server


So, runat="server" must be placed inside the form tag.
<form id="formname" method="post" runat="server">

...but the Soon is eclipsed by the Moon
 
Old July 9th, 2003, 10:38 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

   If I put <form id="formname" method="post" runat="server">, the current page (holidaypage.aspx) won't be able to forward to holidayresponse.aspx when I click on submit button. It just stay on the current page when I click on submit!

Quote:
quote:Originally posted by NotNowJohn
 
Quote:
quote:Control 'FullName' of type 'TextBox' must be placed inside a form tag with runat=server


So, runat="server" must be placed inside the form tag.
<form id="formname" method="post" runat="server">

...but the Soon is eclipsed by the Moon
 
Old July 9th, 2003, 11:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Sorry, I have not seen that you send the form to another page.
Well, ASPX page is powerful when the page is posted to itself. In your case - you just send the form to some page, so, you don't need aspx page, you can use .html page.

...but the Soon is eclipsed by the Moon
 
Old July 9th, 2003, 08:21 PM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

  Is there anyway that I can redirect to the page(holidayresponse.aspx) from holidaypage.aspx page without changing it to .html? However, this code example is from the Wrox book. This means that the book's code have bugs?

Quote:
quote:Originally posted by NotNowJohn
 Sorry, I have not seen that you send the form to another page.
Well, ASPX page is powerful when the page is posted to itself. In your case - you just send the form to some page, so, you don't need aspx page, you can use .html page.

...but the Soon is eclipsed by the Moon
 
Old July 9th, 2003, 10:43 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
  I have this problem too.
  I guess that there is something wrong with the framework SDK.In this book,the author use beta 2(v1.0.29.14).But i use v1.1.
 
Old July 10th, 2003, 09:27 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

   So how can we correct this problem?
 
Old July 10th, 2003, 11:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Well, If you insist...
on holidaypage.aspx you have to add this lines at the top of page:
Code:
<%@Page language="c#"  ClassName="HolidayPage" %>
<script  runat="server" >
public string HPFullName
   {
      get
      {
         return FullName.Text;
      }
   }

public string HPAddress
   {
      get
      {
         return Address.Text;
      }
   }

public string HPSex
   {
      get
      {
         return ************.SelectedItem.Text;
      }
   }

public string HPDestination
   {
      get
      {
         return Destination.SelectedItem.Text;
      }
   }


  void Page_Load()
  {
    if (IsPostBack)
    {    
        Server.Transfer("holidayresponse.aspx");
    }
  }
</script>
On the holidayresponse.aspx you have to add at the top of page:
Code:
<%@ Reference Page="holidaypage.aspx" %>
 HolidayPage hp;
void Page_Load()
  {

        hp = (HolidayPage)Context.Handler;
    Response.Write("<b>Name:</b> " + hp.HPFullName + "<br />");
    Response.Write("<b>Address:</b> " + hp.HPAddress + "<br />");
        Response.Write("<b>************:</b> " + hp.************ + "<br />");
        Response.Write("<b>Destination:</b> " + hp.HPDestination + "<br />");
  }
</script>
That't it! ;)

...but the Soon is eclipsed by the Moon
 
Old July 10th, 2003, 10:18 PM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi NotNowJohn,

   Sorry for troubling u again. I cpoied and pasted your code but I got a compilation error saying that


Compiler Error Message: CS1014: A get or set accessor expected

Source Error:

Line 4: public string HPFullName
Line 5: {
Line 6: get
Line 7: {
Line 8: return FullName.Text;
 
Old July 22nd, 2003, 09:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default

Hi,

The way I see it now, you have two options if you want to submit a .NET form to another page. You can't do it if you put the runat="server" attribute to the form element since .NET forms ALWAYS post back results to themselves.

If you will use the code that was given to you above, you need to add the following to each property block to compile it properly:

    public string HPFullName
    {
       get {
          return FullName.Text;
       }
       set {
          FullName.Text = value;
       }
    }

The other way you can submit to a different page would be to omit the runat attribute from the form and use HTMLControls instead. These are just plain html elements like <input> or <select>, but they all have the runat attribute, like so:

    <input type="text" id="FullName" runat="server" />

They work basically the same way as webcontrols and you will still be able to access their properties individually through codebehind. Taking your original code, it would become something like the following:

<html>
<head>
  <title>Holiday page</title>
</head>
<body>
  <form action="holidayresponse.aspx" method="post">
    <h1>Feiertag Holidays</h1>
    Please enter your details here.
    <br /><br />
    Name:<input type="text" id="FullName" runat="server" />
    <br /><br />
    Address:<textarea id="Address" rows="5" runat="server" />
    <br /><br />
    ************ -
    <input type="radio" name="************" value="Male" runat="server" />
    <input type="radio" name="************" value="Female" runat="server" />
    Please select the destination you would like details on:
    <select id="Destination" runat="server">
      <option value="Madrid">Madrid</option>
      <option value="Barcelona">Barcelona</option>
      <option value="Lisbon">Lisbon</option>
      <option value="Oslo">Oslo</option>
      <option value="Prague"></option>
    </select>
    <br /><br />
      <input type="Submit">
    <input type="Reset">
  </form>
</body>
</html>


Cheers!
Marlon





Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net 2 accessing sql database code problem... minstrel ASP.NET 2.0 Basics 1 August 31st, 2006 11:40 PM
odbc user dsn in asp.net problem with code ashu10dec ASP.NET 1.0 and 1.1 Professional 0 February 23rd, 2006 09:49 AM
Can'T find code to Beginning Asp.net using VB.NET darruler All Other Wrox Books 1 August 12th, 2004 05:04 PM
Help 'beginning asp.net using vb.net' source code jkmf Wrox Book Feedback 1 January 18th, 2004 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.