What is a cross page posting?

Asked 07-Dec-2019
Viewed 731 times

1 Answer


0

Into the ASP.NET by default, submits the form to the same page. The cross-page posting is submitting the form to a different page. It is usually required when you are creating a multi page form to collect information from the user on each page. If moving from the source to the target page, the values of controls in the source page can be accessed in the target page.

When we want to use the cross-page posting, then first we have to use the PostBack URL attribute to specify the page you want to post to.

Here these steps are given below : Like

Step(1): Create a new ASP.NET website called CrossPagePosting. Mostly by default, the website is created with a single webpage, Default.aspx. Firstly A Right click the project in the Solution Explorer > Add New Item >Web Form. And Keep the original name Default2.aspx and click ‘Add’. A website will now contain two pages, Default.aspx and Default2.aspx.

Step (2):- In the source page, Default.aspx, drag&drop a button on the form. And set a text of the button as ‘TargetButton’. And after Set the ‘PostBackUrl’ property of a Button to the URL of the target page, Default2.aspx. 

<asp:Button ID="Button1" runat="server" PostBackUrl="~/Default2.aspx" Text="TargetButton" /></div>

  Step 3:- On the target page Default2.aspx, drop a label on the page from the toolbox. 

Step 4:- Into the Page_Load() of Default2.aspx, you can then access the ‘PreviousPage’ property to check if the page is being accessed as Cross Page postback.

protected void Page_Load(object sender, EventArgs e)

{
       if (Page.PreviousPage != null)
       {
         }
}

Read More :- Cross Page Posting