View Single Post
  #1 (permalink)  
Old January 26th, 2004, 06:34 PM
dati dati is offline
Registered User
 
Join Date: Jan 2004
Location: , NSW, Australia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dati
Default HowTo Pass Form data from Page1.aspx to Page2.aspx

Hi,

I am currently studying the book (Beginning ASP.NET using VB.NET: ISBN: 1861005040 (Published Year: 2001)).

I am stuck at the code pass from Page1.aspx to Page2.aspx, I think it could be todo with the ASP.NET Version. I am using Microsoft.NET Framework v1.1.4322.

I have try putting the runat="server" in the Form section, to get rid of the error, but the submit does not Work.

I know how to extract the data from the same page, but since I am start to learn ASP.NET that's why I want to know why this method of passing from page1 to page2 doesn't work.

Please see the following code.

Thanks in advance.

Regards Dat.

Code:
Page1.aspx
-------------------------------------------------
Code:
<html>
<head>
    <title>Datagrid Control example</title>
</head>
<body>
    <form action="Page2.aspx" method="post" <s>runat="server"</s>>
        <p>
            Enter Your Name: 
            <asp:TextBox id="TextBox1" runat="server" />
        </p>
        <p>
            <input type="submit" value="Submit" />
            <input type="reset" value="Reset" />
        </p>
    </form>
</body>
</html>
Page2.aspx
-------------------------------------------------
Code:
<%@ Page Language="VB" %>
<script runat="server">

    Sub Page_Load()
            Message1.text = Request.Form("TextBox1")
    End Sub
</script>
<html>
<head>
    <title>datacontrol response</title>
</head>
<body>
    <p>
        <asp:Label id="Message1" runat="server" />
    </p>
</body>
</html>
Error When running Page1.aspx
Server Error in '/5040' Application.
---------------------------------------------------------------------
Control 'TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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



Corrected Code:
Page1.aspx

Code:
<script>
    Public Sub Button1_Click(sender As Object, e As System.EventArgs)
        Server.Transfer("Page2.aspx",True)
    End Sub
</script>
<html>
<head>
    <title>Datagrid Control example</title>
</head>
<body>
    <form runat="server">
        <p>
            Enter Your Name: 
            <asp:TextBox id="TextBox1" runat="server" />
        </p>
        <p>
            <asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </p>
    </form>
</body>
</html>

The red highlighted code are the new code.