Click here to Skip to main content
15,790,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to move on second page from first page.

Case 1: If I do document.form.submit() in javascript on first page. Control goes to 2nd page and persists all the hidden fields of first page and URL gets changnes.

Case 2: I did server.transfer at server eventof a button it also goes to 2nd page persisting all the hidden fields but keeping the URL same as teh first.

Case 3: I did Response.Redirect, this time url changned and on 2nd page NO hidden field was persisted !!

Please provide me inputs as why I am getting three different outcomes in these approaches. And can I not persist the hidden fields in response.redirect ?

Thanks in advance.


Cheers ~
Divya
Posted

Let me answer the next part of your question. I will paste your question here from the comments section.
Thanks for quick reply. I am clear about the server.transfer and response.redirect. But as case 1 in my question it persists the hidden fields (showing charactor of .transfer) and changes URL (showing redirect effect). I dont understand why so .. Please help.

Here is your case one -
Case 1: If I do document.form.submit() in javascript on first page. Control goes to 2nd page and persists all the hidden fields of first page and URL gets changes.

There is a lot you need to understand.

When you say form.submit() you are submitting the form to the server. The data gets posted back to the web page which is determined by the 'action' attribute of the form that you are submitting. So the hidden field is also available to the posted page.
You may post back to the same page, which is the default behavior for a ASP.NET page.
When you redirect the page using Response.Redirect, it redirects you to a different server (can be same). So by default the values should not available to the redirected page. (Http is a stateless protocol, you know that).

You need to read more about Server.Transfer and Response.Redirect methods. Also you need to understand the page life cycle of ASP.NET page. Link: MSDN: ASP.NET Page Life Cycle Overview[^]

And yes, there is a very good article on MSDN about navigation options in ASP.NET. Here it is: MSDN: Redirecting Users to Another Page[^]

Read it, I am sure all your doubts will be clear. :thumbsup:

I may not be very clear in my answer. Let me know if you have any doubts.
 
Share this answer
 
v2
Comments
Divymital 16-Dec-10 8:21am    
Thanks Ankur it cleared a lot of things. So it seems like form.submit() is a better approach to redirect as it full fills gives the facilities of both .transfer and redirect. Does this case 1 effect the performance of the 2nd page as it carries all the data in request form to next page.

Thanks again man.. :)
Ankur\m/ 16-Dec-10 8:30am    
My friend you are still not clear. If 1st option would have been the best approach, the other options would probably not be there at all.
I mean, each option has their own use. Choosing between them depends on your scenario. I guess you have not read the "MSDN - Redirecting Users to Another Page" article thoroughly. I suggest you to give that a thorough reading, you will understand what are the navigation options available in asp.net and when to use them. If you still have doubts, feel free to ask me for an explanation.
 
Share this answer
 
Comments
Divymital 16-Dec-10 7:07am    
Thanks for quick reply. I am clear about the server.transfer and response.redirect. But as case 1 in my question it persists the hidden fields (showing charactor of .transfer) and changes URL (showing redirect effect). I dont understand why so .. Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900