Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: problem with chapter 3 beginning asp.net using c# ( passing variable to another aspx page)


Message #1 by mathew2002it@y... on Sat, 13 Apr 2002 12:37:08
Hi,

I have some problems with the example given in chapter 3 Beginning ASP.net 
using C#. When i run the holidaypage.aspx, error occured as written in the 
browser as follow:

Exception Details: System.Web.HttpException: Control 'FullName' of 
type 'TextBox' must be placed inside a form tag with runat=server.

After i put the runat="server" inside the form tag, there was no error but 
when the submit button was pressed, the value from the form seem like not 
passing to the second aspx page (holidayresponse.aspx). It just stay on 
the same page. When i view the source in the browser, i found out that the 
form tag generated as below

<form name="_ctl0" method="post" action="holidaypage.aspx" id="_ctl0">

has the action attribute that link to the same holidaypage.aspx and not 
holidayresponse.aspx. I think that's why all the value from the form is 
not passing to holidayresponse.aspx. Does anyone has any idea to overcome 
this problem of passing value to another aspx page. Thank you. 

Mathew

These are the original source codes downloaded from wrox
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                         holidaypage.aspx
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

<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 />
    Sex - 
    <asp:radiobuttonlist id="sex" 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>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                      holidayresponse.aspx
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<script runat="server" language="c#">
  void Page_Load()
  {
    Response.Write("<b>Name:</b> " + Request.Form["FullName"] + "<br />");
    Response.Write("<b>Address:</b> " + Request.Form["Address"] 
+ "<br />");
    Response.Write("<b>Sex:</b> " + Request.Form["Sex"] + "<br />");
    Response.Write("<b>Destination:</b> " + Request.Form["Destination"] 
+ "<br />");
  }
</script>
<html>
<head>
  <title>Holiday page</title>
</head>
<body>
  <br /><br />
  These details have been entered into our database, you should receive a 
  confirmation email from us shortly.
<br /><br />
</body>
</html>


  Return to Index