<html><head runat="server"> <title>Example: Posting the Data to Another ASP.Net Page</title></head><body><!-- Example for Cross Page Posting PostBackUrl Property is used to post the data to another asp.net page --> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label> <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br /> <asp:Button ID="btnSend" runat="server" Text="Send" PostBackUrl="~/post2.aspx"/> </div> </form></body></html>
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Reading the data from First Post1.aspx page</title></head><body><!-- Example for Cross Page Posting --> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> Welcome to New Session <br /> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Post1.aspx">Back</asp:HyperLink> </div> </form></body></html>
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class post2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { /* PreviousPage - Refers to the previous page which posted the data FindControl - Used to refer to the Control in another page and it takes control name as a parameter. */ TextBox txt = (TextBox) PreviousPage.FindControl("txtName"); Label1.Text = txt.Text; }}