Cross -Page Posting in ASP.NET Web Pages

ASP.NET by default submit the forms to the same pages, cross page posting is submitted the form to a different page. This is usually required when you are creating a multipage form to collect information from the user on each page. when moving from the source to the target page.

"To use cross-page posting, you have to use the "postBackUrl" attribute to specify the page we want to post".

Example

Step 1: Add two webform "default.aspx" and "default2.aspx"

Step 2: On default.aspx, drop down a button & set textproperty of this button as targetpage.

Set the "postbackurl" property of a button to the url targetpage, default2.aspx.

Step 3: On default2.aspx drop down a lable.

Step 4: In the page load event of default2.aspx

We can access "previouspage" property to check if the page is bring accessed as cross page postback.

proctected void page_load( object sender , eventArgs e)
{
     if( page.previouspage ! =null)
    {
    }
}

Step 5: To redirect the value from the source page you must access control using the "findcontrol()" method of the the previouspage

we will accessing the text propertyof the button control in "default.aspx"

proctected void page_load( object sender , eventArgs e)
{
    if(page.previouspage !=null)
   {
        button btn = (button)(page.previouspage.findcontrol(button1));
        lable1.text =btn.text;
    }
}
 

Step 6: Right click on default.aspx and set s start page

Now run application and click button we will see that the page is posting to default2.aspx.