Changing the action attribute on the form has no effect as .Net always changes it to post to itself. Changing the action in this way posts to the second page but then gives this error:
<form id="Form1" method="post" runat="server" onSubmit="this.action = 'TestPost2.aspx'"
"The View State is invalid for this page and might be corrupted. "
I would rather not use a querystring or sessions. Most suggestions seem to use server.transfer but that has a huge defect because it causes the browser url to not match up with the page's contents, which would be confusing to users. Does anyone have a solution for this? Thanks.Let it post to the search page, then do a Server.Transfer to the list page.
But then the List page says Search.aspx in the url even though it is showing the List pages Contents. Clicking a Back server button on the List page and doing a server.transfer back to the Search page (to restore the original search criteria) would show the List.aspx as the url with the Search page contents in it.
It seems like there should be a way to override the form action and still use runat = server for the form.
Then use Response.Redirect and put the search term in the querystring.
In the on load event:
Add this to the button that submits the search:
Button2.Attributes.Add("onclick","document.forms[0].action='mylistpage.aspx'");
Like I said in the original post I would like to know how to do a form post without using a querystring or sessions or server.transfer which causes a mismatch between what is displayed on the page and the browser's url.
I tried using this as suggested but it gives the following error.
Button2.Attributes.Add("onclick","document.forms[0].action='mylistpage.aspx'");
"The View State is invalid for this page and might be corrupted. "
That is to be expected... The reason is because the _VIEWSTATE and other information will be transfered over to the other page in a post and the other page thinks it belongs to it.
What you are trying to do is not how you normally work in .NET, but hey!, you asked a question and we will get you an answer :-P
What about if you call a function:
Button2.Attributes.Add("onclick","postToForm('myform')");
and then use a javascript function
function postToForm(action) {
document.forms[0].action=action;
document.forms[0].__VIEWSTATE = '';
document.forms[0].submit();
}
I haven't tried it...
This line gives an error:
document.forms[0].__VIEWSTATE = '';
"Object doesn't support this property or method."
"Do you want to continue running scripts on this page?"
Answered yes, then it goes to page 2 and displays error:
"The View State is invalid for this page and might be corrupted."
document.forms[0].__VIEWSTATE.value = '';
That fixed the javascript error. But I still get this after the post to page2:
The View State is invalid for this page and might be corrupted.
0 comments:
Post a Comment