In ASP.NET 2.0 , cross page posting feature was introduced . This allows one to fire a normal post back to a different page in the application. In the target page, one can then access the values of server controls in the source page that initiated the postback.
To use cross page posting, one can set the PostBackUrl property of a Button, LinkButton or ImageButton control, which specifies the target page.
In the target page, one can access the PreviousPage property to retrieve values from the source page. By default, the PreviousPage property is of type Page, so you must access controls using the FindControl
method. You can also enable strongly-typed access to the source page by setting the @PreviousPageType directive in the target page to the virtual path or Type name of the source page.
√ Create a Web Form Source.aspx 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 example in this case it is "Target.aspx"
Now how to access Source page controls value in target page :
Page sourcePage = this.PreviousPage;
Then you can find any control from the previous page and read its state:
TextBox sourceTextBox = sourcePage.FindControl("TextBox1")).Text;
string value = sourceTextBox.Text;
No comments:
Post a Comment