Tuesday, January 13, 2009

Cross Page Posting

By using cross Page Posting We can access controls or properties in the previous page from the current page.

Suppose We have a textbox in Default.aspx named txtName,So create a property returning its text,


public string Name
{
get
{
return txtName.Text;
}
}
we have a hyperlink and its NavigateUrl is default2.aspx.
In Default2.aspx set PreviousPageType in the source,

<%@ PreviousPageType VirtualPath="~/New/Default.aspx"%>
and in the code behind access the property Name from the first page like this,

if (IsCrossPagePostBack)
{
lblName.Text= PreviousPage.Name;
}
in the second page.

0 comments:

Post a Comment