What is cross page posting?

 Posted by ArticlesMaint on 9/17/2009 | Category: ASP.NET Interview questions | Views: 6291

Note: - This is a new feature available in ASP. NET 2.0.

By default, button controls in ASP. NET pages post back to the same page that contains the button, where you can write an event handler for the post. In most cases this is the desired behavior, but occasionally you will also want to be able to post to another page in your application. The Server. Transfer method can be used to move between pages, however the URL does not change. Instead, the cross page-posting feature in ASP .NET 2.0 allows you to fire a normal post back to a different page in the application. In the target page, you can then access the values of server controls in the source page that initiated the post back.

To use cross page posting, you can set the PostBackUrl property of a Button, Link Button or Image Button control, which specifies the target page. In the target page, you can then access the Previous Page property to retrieve values from the source page. By default, the Previous Page property is of type Page, so you must access controls using the Find Control method. You can also enable strongly-typed access to the source page by setting the @Previous Page Type directive in the target page to the virtual path or Type name of the source page.

Here is a systematic guide for implementing the cross-page post back using controls that implement the I Button Control interface.
• Create a Web Form and insert a Button control on it using the VS .NET designer.
• Set the button's PostBackUrl property to the Web Form you want to post back. For instance in this case it is "nextpage.aspx"

<asp: Button ID="Button1" run at="server" PostBackUrl="~/nextpage.aspx" Text="Post to next page" />

When the PostBackUrl property of the I Button Control is set, the ASP .NET framework binds the corresponding HTML element to new JavaScript function named Web Form _Do Post Back With Options. The corresponding HTML rendered by the ASP .NET 2.0 will look like this:

<input type="submit" name="Button1" value="Post to Page 2" on click="java script: Web Form_ Do Post Back With Options (new Web Form_ Post Back Options("Button1", ",false”,"Page2.aspx", false, false))" id="Button1" />

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response