Value Transfer between pages. value transfer between pages
1. Session Method
A. PASS Parameters in aspx, and click control function.
Protected void LinkButton1_Click1 (object sender, EventArgs e) {String strId = txtCid. Text; Session ["C_Id"] = strId; // record C_ID Server. Transfer ("~ /Emp/Employee. aspx ");}
B. aspx receiving Parameters
String vCId = Session["C_Id"].ToString();
2. Pass the value in the address bar
A. Parameters in the aspx Button Function
protected void LinkButton1_Click1(object sender, EventArgs e){ String strId = txtCid.Text; Response.Redirect("~/emp/Employee.aspx?C_Id=" + strId);}
B. aspx receiving Parameters
String vCId = Request.QueryString["C_Id"].ToString();
To pass two or more parameters, use "&" to add them, for example:
Response.Redirect("~/emp/UpdateEmployee.aspx?E_Id="+strEID + "&C_Id="+strCID);
Comparison of the two methods: Method 1: Use Server. Transfer to pass a value without changing the address bar. If a value is added to the address bar, an error is reported and the transmitted data may be lost later.
Method 2: enter a value in the address bar to go to the corresponding page, for example, if the entered value is correct or an error is reported.
Transfer values between html pages
First, make it clear that the HTML page cannot accept the form request value. However, JS can be used in the HTML page. We can use JS to manually implement something.
In JS, the complete address can be obtained using the window. location. href attribute, so our parameters can be passed in the GET mode, that is, the method of the form = "GET"
Below is a function constructed in JS to get the value submitted in get mode.
Function Request (strName)
{
Var strHref = too many Doc ument. location. href;
Var intPos = strHref. indexOf ("? ");
Var strRight = strHref. substr (intPos + 1 );
Var arrTmp = strRight. split ("&");
For (var I = 0; I <arrTmp. length; I ++)
{
Var arrTemp = arrTmp [I]. split ("= ");
If (arrTemp [0]. toUpperCase () = strName. toUpperCase () return arrTemp [1];
}
Return "";
}
Usage:
Var id = Request ("id ");
Document. write (id );
With this function, we can set the value on the test3 page. Pay the obtained value to the value attribute of the text box.
The Code is as follows:
Test2.htm
<Title> test2 </title>
<Form method = get action = "test3.htm">
<Input name = "abc"> <input type = "submit" value = "submit">
</Form>
Test3.htm
<Script>
Function Request (strName)
{
Var strHref = too many Doc ument. location. href;
Var intPos = strHref. indexOf ("? ");
Var strRight = strHref. substr (intPos + 1 );
Var arrTmp = strRight. split ("&");
For (var I = 0; I <arrTmp. length; I ++)
{
Var arrTemp = arrTmp [I]. split ("= ");
If (arrTemp [0]. toUpperCase () = strName. toUpperCase () return arrTemp [1];
}
Return "";
}
</Script>
<Title> test3 </title>
<Form method = get action = "test3.htm" name = myform>
<Input name = "abc" va ...... remaining full text>
In JavaScript, how does one pass values between pages?
The index.htm file transmits parameters in the url:
<A href = "aaa.htm? "> Example 1 </a> <a href =" aaa.htm? ID = 23 "> Example 2 </a> <a href =" aaa.htm? ID = 67 & Name = cool "> Example 3 </a>
Parameters for receiving the aaa.htm file:
<Script language = "javascript">
Var tmpArr, QueryString;
Var URL = document. location. toString ();
If (URL. lastIndexOf ("? ")! =-1 ){
QueryString = URL. substring (URL. lastIndexOf ("? ") + 1, URL. length );
TmpArr = QueryString. split ("&");
For (I = 0; I <= tmpArr. length; I ++)
{Try {eval (tmpArr [I]);}
Catch (e ){
Var re = new RegExp ("(. *) = (. *)", "ig ");
Re.exe c (tmpArr [I]);
Try {eval (RegExp. $1 + "=" + "\" "+ RegExp. $2 + "\"");}
Catch (e ){}
}
}
}
Else
{
QueryString = "";
}
</Script>
<Script language = "javascript">
Document. write ("query string:" + QueryString + "<br> ");
If (typeof (ID )! = "Undefined ")
{Document. write ("ID value:" + ID + "<br> ");}
If (typeof (Name )! = "Undefined ")
{Document. write ("Name value:" + Name + "<br> ");}
</Script>
Wish you success ^_^