consider the following example...
1.Create a web page named default.aspx(say)like following,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="HP_Master_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label>
<asp:TextBox ID="txtFN" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Last Name"></asp:Label>
<asp:TextBox ID="txtLN" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="SUBMIT" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
and in Default.aspx.cs,like following
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class HP_Master_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["FN"] = txtFN.Text;
Session["LN"] = txtLN.Text;
Response.Redirect("Default2.aspx");
}
}
what i have done is
1.Created a page,and added server controls from tool bar,Label1,Label2,txtFN,txtLN, and a Button
2.Added onclick event to button,and in code behind created two sessions to carry the values entered in the two text boxes,Session["FN"],and Session["LN"],then the page is redirected to another page "Default2.aspx" on button click
3.Default two cantains two server controls LblFN,andlblLN that contain no values initially
4.When the page is loaded as soon as the button in previous page is clicked,in the current pages page load event,the text property of labels lblFN,and lblLN are set with the values stored in the Session variables.the code for this is as per following
default2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="HP_Master_Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblFN" runat="server" Text=""></asp:Label>
<asp:Label ID="lblLN" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
default2.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class HP_Master_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblFN.Text = Session["FN"].ToString();
lblLN.Text = Session["LN"].ToString();
}
}