1.11M Members

PostBackURL vs. Response.Redirect

 
0
 

What really is the difference between the two? and when should each of them be used? Can we use Response.Redirect in place of PostBackURL?

Thanks in advance.

 
0
 

PostBackURL is more equivalent to Server.Transfer than Response.Redirect.
It maintains ViewState and all the rest of the Page object and other State Bags.

Response.Redirect simply sends a 302 to the browser.

Also, PostBackURL simply sets a CLIENT-SIDE script event on a button. So it doesn't work in all situations. Server.Transfer stays on the server.

 
0
 

I tried PostBackURL and PreviousPage properties to get some values to another form. But I have to submit the page twice to go to the next page.

Why is that?

 
0
 

Probably because you're setting PostBackURL in the same spot you're trying to use it.
PostBackURL is written out as client-side javascript on a button. If it is not set already at design time, you will see a need for 2 postbacks; one to set it and it gets written to the client, the next actually submits with the new PostBackURL.

 
0
 

how do I make my postbackurl link to the new webpage without clicking it twice

 
0
 

PostBackURL sends all the form data to the assigned page.
Whereas when using Response.Redirect your sending the form data to your current page then moving your user to the assigned page.

So if your going to handle the form data on a separate page then you set the PostBackURL.
Otherwise, if your current page code handles the form data you do a Response.Redirect.

If you are using PostBackURL. Set it using the properties in the html/design view, or on page_load to make it work without clicking twice.

 
-1
 

What really is the difference between the two? and when should each of them be used? Can we use Response.Redirect in place of PostBackURL?

Thanks in advance.

postback is most often used to process some code on server and calling the page itself again. whereas response.redirect is used to transfer control to another page.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article