|
 |
aspx_beginners thread: Problem with code example - Submitting form to another page
Message #1 by "h. branyan" <hb@t...> on Fri, 15 Mar 2002 10:41:26 -0500
|
|
Just began going through _Beginning ASP.NET using VB.NET_ yesterday. At the
end of chapter 3 there is an exercise I'm having trouble with. The form on
holidaypage.aspx needs to submit to holidayresponse.aspx. The code in the
book does not work for me - It does not submit to the holidayresponse.aspx
page, but to itself.
Here is the code:
<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>
Thanks,
Hillarie
Message #2 by "hillarie branyan" <hb@t...> on Mon, 18 Mar 2002 15:46:56
|
|
Hi again - I decided to continue on through chapter 4 (Variables) and the end of chapter exercise
involves reusing these 2 pages. I am at a lost as to how to submit to another page. Would appreciate some help.
Thanks, Hillarie
As Posted March 15:
> Just began going through _Beginning ASP.NET using VB.NET_ yesterday. At the
>end of chapter 3 there is an exercise I'm having trouble with. The form on
>holidaypage.aspx needs to submit to holidayresponse.aspx. The code in the
book
> does not work for me - It does not submit to the holidayresponse.aspx
page, but to itself.
>Here is the code:
<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>
Message #3 by "Dan McKinnon" <mddonna@q...> on Mon, 18 Mar 2002 19:33:59
|
|
Hi Hillarie -
You've opened up a can of worms, at least as far as I'm concerned. Last
month I posted the post below to this forum:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<
Hi -
I am working my way through "Beginning ASP.NET using VB.NET". I was
especially interested in Microsoft's new take on form controls in Chapter
3. On page 126 there is a page named holidaypage.aspx that is a form page
that submits info to holidayresponse.aspx, which processes it. The problem
is that the textbox control that is runat = server must be contained in a
form that is also runat = server. I looked at the erratta for this book,
and sure enough, there was some workaround code submitted by Alessandro
Ansa. His solution was to nest another form with its runat attribute set
to server within the form that has an action attribute of another page and
no runat attribute set.
Apparently the default behavior of an aspx runat = server form is always
to submit its info to itself. In fact its beyond default, as when I set
the runat attribute to server and tried to put in an action attribute of a
second page (which is so very very common in .asp pages) it would not
accept it and changed the source code to submit it back to itself.
At any rate, I could not get even the supposedly good erratta code to
work. The first page displayed fine, but when the submit button is
clicked, it always gives me an error page saying the View_State of the
second page may be corrupted. I tried copying the code of both pages into
files with different names, restarting browser, IIS, rebooting computer,
etc. and I could not get the second page to display. It was always the
same message:
Server Error in '/' Application.
---------------------------------------------------------------------------
-----
The View State is invalid for this page and might be corrupted.
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: The View State is invalid for
this page and might be corrupted.
Source Error:
An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): The View State is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +150
System.Web.UI.Page.LoadPageViewState() +16
System.Web.UI.Page.ProcessRequestMain() +421
Any help is appreciated. As I go on in the book, one of the next exercises
in Chapter 4 builds on this example, so I would like to get some
resolution.
Thanks,
Dan
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
And here was the only answer I got:
The short answer is to put the following line at the beginning of the
holidayresponse.aspx page.
<%@ Page EnableViewStateMac="false" %>
Doug
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>
Which helped, but didn't answer my question about posting to another page.
If you find out how to do it, please let me know.
Thanks,
Dan
Message #4 by allan@a... on Sat, 30 Mar 2002 04:10:55
|
|
code for the page holidaypage.aspx (note that I shortened it for clarity)
of particular note is the nested forms. the inner one does not use the
action property, not sure that it even needs the method="post", but I did
not try it without it.
<html>
<head>
<title>Holiday page</title>
</head>
<body>
<form action="holidayresponse.aspx" method="post" >
<form method="post" runat="server">
<h1>Feiertag Holidays</h1>
Please enter your details here.
<br /><br />
Name:<asp:textbox id="FullName" runat="server" />
<br /><br />
<input type="Submit">
<input type="Reset">
</form>
</form>
</body>
</html>
here is the code for the holidayresponse.aspx (note the first line that
Dan or Doug gave in reply)
<%@ Page EnableViewStateMac="false" %>
<script runat="server" language="vb">
Sub 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 />")
End Sub
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Holiday Page</title>
</head>
<body>
<br /><br />
These details have been entered
<br /><br />
</body>
</html>
If i can be of more assistance, just send me an email, but keep in mind
that I am a beginner also.
Good luck!
-->Allan
> Just began going through _Beginning ASP.NET using VB.NET_ yesterday. At
the
end of chapter 3 there is an exercise I'm having trouble with. The form on
holidaypage.aspx needs to submit to holidayresponse.aspx. The code in the
book does not work for me - It does not submit to the holidayresponse.aspx
page, but to itself.
Here is the code:
<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>
Thanks,
Hillarie
|
|
 |