This is new Concept Introduce in Asp.net 2.0, This is used to Passing the values from one page to Certain page using PostbakUrl property for Button, LinkButton, and Image Button from that easily values can be access by prevoius page
Below is example For the Cross Page posting,
This can be achieved following 3 ways
1)Server.Transfer("PageUrl");
2)Response.redirect(" PageUrl")
3)PostbackUrl("PageUrl")
This Example Contains Source.aspx and Destination.aspx ,2 Pages
In Source.aspx
------------------------------
First Name:<asp:TextBox ID="FirstName" runat="server"></asp:TextBox><br />
Last Name:<asp:TextBox ID="LastName" runat="server"></asp:TextBox><br />
<br />
<asp:ImageButton ID="ImageButton1" ImageUrl="~/Image.jpg" Height="30" Width="40" runat="server" PostBackUrl ="~/DestinationPage.aspx" />
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/DestinationPage.aspx">LinkButton</asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="Submit To Destination Page"
PostBackUrl ="~/DestinationPage.aspx" /><!--onclick="Button1_Click1" />
---------------------------------
In Source.aspx.cs
public string FormFirstName
{
get { return FirstName.Text; }
}
public string FormLastName
{
get { return LastName.Text; }
}
protected void Page_Load(object sender, EventArgs e)
{
if ((PreviousPage != null)&& (PreviousPage.IsCrossPagePostBack))
{
Page previousPage = PreviousPage;
TextBox firstName = (TextBox)previousPage.FindControl("FirstName");
TextBox lastName = (TextBox)previousPage.FindControl("LastName");
}
protected void Button1_Click1(object sender, EventArgs e)
{
Server.Transfer("DestinationPage.aspx");
}
-------------------------------
DestinationPage.aspx
<asp:Label ID="labelFirstName" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="labelLastName" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="nametxt" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"/>
--------------------------------
DestinationPage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string str = Request.Form["FirstName"];
//if ((PreviousPage != null) || (PreviousPage.IsCrossPagePostBack))
if((!Page.IsPostBack) || (PreviousPage.IsCrossPagePostBack))
{
SourcePage prevPage = PreviousPage;
labelFirstName.Text = prevPage.FormFirstName;
labelLastName.Text = prevPage.FormLastName;
}
else if ((PreviousPage!=null) ||(PreviousPage.IsCrossPagePostBack))
{
SourcePage prevPage = PreviousPage;
// we can now use the values from textboxes and display them in two Label controls..
labelFirstName.Text = prevPage.FormFirstName;
labelLastName.Text = prevPage.FormLastName;
}
}
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.