Subject: Error Pass Form data from Page1.aspx to Page2.aspx
Posted By: dati Post Date: 1/25/2004 7:16:11 PM
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
-------------------------------------------------

<html>
<head>
    <title>Datagrid Control example</title>
</head>
<body>
    <form action="Page2.aspx" method="post" runat="server">
        <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
-------------------------------------------------

<%@ 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.

Reply By: bmains Reply Date: 1/27/2004 12:58:27 PM
Hello,

I don't have the book you are using, so I don't know specifically what it is trying to do.  You may be able to change:

<asp:TextBox id="TextBox1" runat="server" />


into
<input type="Text" id="TextBox1"/>


You can do this because you are referencing the value of the textbox through the request.form() collection.

Or you can leave the <asp:TextBox>, change the form to include the "runat='server'", Change the submit button to include the "runat='server'" or change it to a web control, and use the Server.Transfer() method to redirect to the second page.  Keep in mind that when you use Server.Transfer (make sure the second parameter is set to true; this preserves the previous form state) that the browser will still show "page1.aspx" in the address bar.

Lastly, keep in mind that .NET doesn't allow posting to another form.  To do this in .NET, you can do it in several ways.  You can store the values that are posted back in the Session, you can use javascript to redirect (I saw an article on the web), or you can use the Server.Transfer() or Server.Execute() methods.

Brian
Reply By: dati Reply Date: 1/28/2004 1:27:44 AM
Thank your for your comments Brian,

I've posted in the following area as well and have found the answer I needed. (ie. the posting of the form from page1 to page2 is not supported) as you have mention it.

I have posted the solution using Server.Transfer here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=9004

Thanks again.


Go to topic 9060

Return to index page 961
Return to index page 960
Return to index page 959
Return to index page 958
Return to index page 957
Return to index page 956
Return to index page 955
Return to index page 954
Return to index page 953
Return to index page 952