1,105,254 Community Members

PostBackURL vs. Response.Redirect

Member Avatar
c# seeker
Newbie Poster
7 posts since Feb 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
nikkiH
Junior Poster in Training
79 posts since Dec 2006
Reputation Points: 2 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
c# seeker
Newbie Poster
7 posts since Feb 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
nikkiH
Junior Poster in Training
79 posts since Dec 2006
Reputation Points: 2 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
awasonia
Newbie Poster
2 posts since Oct 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
plazmo
Posting Whiz in Training
206 posts since Aug 2005
Reputation Points: 1 [?]
Q&As Helped to Solve: 16 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
ghazanfar381
Newbie Poster
3 posts since Jun 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article