Cross-page postback is a feature that makes it possible to post values from one page to another, without Server.Transfer or other far fetched techniques. We all know that in ASP.NET 1.xx you could only post a page back to itself, which was pretty annoying.

What do we do?

The way it works is that all controls that implement the new System.Web.UI.WebControls.IButtonControl got a property called:PostBackUrl

When we have a Button on a WebForm (a Button implements IButtonControl), we set the PostBackUrl to the Webform we want to postback to.

What we get is:

postoneline 

How does it work?

When the PostBackUrl property of the 'IButtonControl' is set, the ASP.NET framework binds the corresponding HTML element to new JavaScript function named 'WebForm_DoPostBackWithOptions'. The corresponding HTML rendered by the ASP.NET 2.0 will look like this:

 

postsubmit

One problem with cross-page posting is the new page presumably needs the view state of the page posted from. The view state is page specific; it contains information, for example, about controls embedded on the particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name, '__POSTBACK' . This field is embedded only when there is an 'IButtonControl' on the page and its 'PostBackUrl' property is set to a non-null value. This field contains the view state information of the poster page. To access the view state of the poster page, you can use the new PreviousPage property of the page:

 

postter

 

And with:

 

posterText2

 

We can find all controls on the posting (previous) page and read it's state.

Henry Cordes
My thoughts exactly...


Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading