Tuesday, October 30, 2007

What is cross page posting in asp.net 2.0

cross page posting is a good feature in asp.net 2.0

Cross-page posting enables you to submit a form (suppose, Page1.aspx) and have this
form and all the control values post themselves to another page (suppose, Page2.aspx). now you can get values of all controls on one web form from other web form

How to do this practically

Add a new website in visual studio 2005 and add two web form (suppose page1.aspx and page2.aspx)

Page1.aspx

Add two controls in this page from tool box, one textbox and one button

/asp:Button ID=”Button1” Runat=”server” Text=”Submit page to Page2.aspx”
PostBackUrl=”Page2.aspx”/

Page2.aspx

Add a label in page 2

protected void Page_Load(object sender, System.EventArgs e)
{
TextBox pp_Textbox1;
pp_Textbox1 = (TextBox)PreviousPage.FindControl(“Textbox1”);
Label1.Text = “Hello “ + pp_Textbox1.Text;
}

No comments: