Webform_1.aspx contents are as follows:
Copy Code code as follows:
<%@ page language= "C #" autoeventwireup= true "codebehind=" WebForm_1.aspx.cs "inherits=" pages are passed values. Webform_1 "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:table id= "Tablelogin" runat= ' Server ' >
<asp:TableRow>
<asp:TableCell><label> User name:</label></asp:tablecell>
<asp:tablecell><asp:textbox id= "UserName" runat= "Server" width= "150px" ></asp:textbox></asp: Tablecell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><label> Password:</label></asp:tablecell>
<asp:tablecell><asp:textbox id= "PassWord" runat= "Server" width= "150px" ></asp:textbox></asp: Tablecell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><label> Authentication Password:</label></asp:tablecell>
<asp:tablecell><asp:textbox id= "confimpwd" runat= "Server" width= "150px" ></asp:textbox></asp: Tablecell>
</asp:TableRow>
<asp:TableRow>
<asp:tablecell><asp:button id= "Confirm" runat= "Server" text= "confirm" width= "50px" onclick= "Confirm_click"/> </asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
The Webform_2.aspx page is as follows:
Copy Code code as follows:
<%@ Reference page= "~/webform_1.aspx"%>
<%@ page language= "C #" autoeventwireup= true "codebehind=" WebForm_2.aspx.cs "inherits=" pages are passed values. Webform_2 "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>
</div>
</form>
</body>
WebForm_1.aspx.cs files are as follows:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Namespace page Pass Value
{
public partial class WebForm_1:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
}
public string un//Get user name
{
Get
{
return username.text;
}
}
public string pwd//Get password
{
Get
{
return password.text;
}
}
public string conpwd//get a confirmation password
{
Get
{
return confimpwd.text;
}
}
<summary>
Passing values to webform_2.aspx pages
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
protected void Confirm_click (object sender, EventArgs e)
{
1:querystring Page Pass Value
String url = "webform_2.aspx?un=" + Username.text + "&userpassword=" + Password.text + "&conpwd=" + confimpwd.te xt
Response.Redirect (URL);
2:session Pass Value
Session["un"] = username.text;
session["pwd"] = Password.text;
session["conpwd"] = Confimpwd.text;
Server.Transfer ("webform_2.aspx");
3: Using a Cookie object to pass the value
HttpCookie cookie_name = new HttpCookie ("un");
Cookie_name. Value = Username.text;
HttpCookie cookie_pwd = new HttpCookie ("pwd");
Cookie_pwd. Value = Password.text;
HttpCookie cookie_conpwd = new HttpCookie ("Conpwd");
Cookie_conpwd. Value = Confimpwd.text;
Response.appendcookie (Cookie_name);
Response.appendcookie (COOKIE_PWD);
Response.appendcookie (COOKIE_CONPWD);
Server.Transfer ("webform_2.aspx");
4: Use the Application object to pass the value, like the session pass the value, the scope global all user
Application["un"] = username.text;
application["pwd"] = Password.text;
application["conpwd"] = Confimpwd.text;
Response.Redirect ("webform_2.aspx");
Server.Transfer ("webform_2.aspx");
}
}
}
WebForm_2.aspx.cs files are as follows:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Namespace page Pass Value
{
public partial class WebForm_2:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
Querytransfer ();
Sessiontransfer ();
Cookietransfer ();
Applicationtransfer ();
Transfer ();
}
public void Querytransfer ()//Receive QueryString value, from webform_1 page value
{
String strusername = request.querystring["un". ToString ();
String strpassword = request.querystring["UserPassword"]. ToString ();
String strpwd = request.querystring["Conpwd"]. ToString ();
Response.Write ("User name" + strusername + "<br/>" + "password is" + strpassword + "<br/>" + "Confirm password is" + strpwd);
}
public void Sessiontransfer ()//Receive session pass value, from webform_1 page value
{
String strusername = session["un". ToString ();
String strpassword = session["pwd"]. ToString ();
String strpwd = session["Conpwd"]. ToString ();
Response.Write ("User name" + strusername + "<br/>" + "password is" + strpassword + "<br/>" + "Confirm password is" + strpwd);
Session.remove ("un");
Session.remove ("pwd");
Session.remove ("Conpwd");
}
The public void Cookietransfer ()//receives the value of the cookie, from the value of the Webform_1 page
{
String strusername = request.cookies["un". Value.tostring ();
String strpassword = request.cookies["pwd"]. Value.tostring ();
String strpwd = request.cookies["Conpwd"]. Value.tostring ();
Response.Write ("User name" + strusername + "<br/>" + "password is" + strpassword + "<br/>" + "Confirm password is" + strpwd);
}
public void Applicationtransfer ()//Receive application value, from webform_1 page value
{
Application.Lock ();
String strusername = application["un". ToString ();
String strpassword = application["pwd"]. ToString ();
String strpwd = application["Conpwd"]. ToString ();
Application.UnLock ();
if (strpassword!= strpwd)
{
Response.Write ("The password you confirmed is wrong, please re-enter!") <br/> ");
Server.Transfer ("webform_1.aspx");
}
Response.Write ("User name" + strusername + "<br/>" + "password is" + strpassword + "<br/>" + "Confirm password is" + strpwd);
}
public void Transfer ()//transfer value, value from webform_1.aspx page
{
Webform_1 WF1;
WF1 = (webform_1) Context.Handler;
string strusername = wf1.un;
string strpassword = Wf1.pwd;
string strpwd = Wf1.conpwd;
Response.Write ("User name" + strusername + "<br/>" + "password is" + strpassword + "<br/>" + "Confirm password is" + strpwd);
}
}
}
I have a limited level, but also invite friends to advise!