HTTPPostSource.aspx.cs
Protectedvoid Button1_Click(object sender, EventArgs e)
{
Button1.PostBackUrl ="~/HTTPPostTarget.aspx";
}
HTTPPostTarget Page
HTTPPostTarget.aspx
<%@Page Language="C#"AutoEventWireup="true"CodeFile="HTTPPostTarget.aspx.cs"
Inherits="HTTPPostTarget"%>
<!DOCTYPEhtml PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
HTTPPostTarget.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartial classHTTPPostTarget : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
Label1.Text ="Posted Value: " + Request.Form["Textbox1"].ToString();
}
}
Now run the application and test it.
Using Public Property
When we use a Public Property we create a a public property and on the next page get it using "PreviousPage.PropertyName". If you have 2 simple pages then one is a PublicPropertySource and the other is a PublicPropertyTarget. I have done it this way.
PublicPropertySource page: This page contains a property.
PublicPropertySource.aspx
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:ButtonID="Button1"runat="server"
OnClick="Button1_Click"Text="Button"/>
PublicPropertySource.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartial classPublicProperty : System.Web.UI.Page
{
public string TextValue
{
get
{
return TextBox1.Text;
}
}
protected void Page_Load(object sender,EventArgs e)
{
}
protected void Button1_Click(object sender,EventArgs e)
{
Server.Transfer("PublicPropertyTarget.aspx");
}
}
PublicPropertyTarget Page
On PublicPropertyTarget.aspx add this on top.
<%@ PreviousPageType VirtualPath="Page1.aspx" %>
PublicPropertyTarget.aspx
<%@Page Language="C#"AutoEventWireup="true"CodeFile="PublicPropertyTarget.aspx.cs"Inherits="PublicPropertyTarget" %>
<%@PreviousPageType VirtualPath="~/PublicPropertySource.aspx"%>
<!DOCTYPEhtml PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
PublicPropertyTarget.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartial classPublicPropertyTarget : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
Label1.Text = PreviousPage.TextValue;
}
}
Now run the application and test it.