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.
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.
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?
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.
how do I make my postbackurl link to the new webpage without clicking it twice
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.
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.