This article briefly introduces no solution for saving and modifying runat = server control values. This is a problem for beginners. If you need it, please refer to it.
| The Code is as follows: |
Copy code |
Function Save () // Save a value that is not a Server Control Value
{
Var 1 = document. getElementById ('1box'). value;
Var 2 = document. getElementById ('2box'). value;
Var TxtValue = 1 + "■" + 2;
Document. getElementById ('3). value = TxtValue;
Return true;
}
Window. onload = function show ()
{
Var TxtValue = document. getElementById ('3). value;
If (TxtValue! = ""){
EachValue = new Array ();
EachValue = TxtValue. split ('■ ');
Document. getElementById ('1box'). value = EachValue [0];
Document. getElementById ('2box'). value = EachValue [1];
}
Return true;
}
html: <input type="text" id="1Box" class="txt-underline" style="width: 60px;text-align:left " maxlength="10"/> <input type="text" id="2Box" class="txt-underline" style="width: 200px;text-align:left" maxlength="30"/>
<input type="hidden" id="3" name="Values" runat="server" /> |
CS:
| The Code is as follows: |
Copy code |
Void LoadData () // page loading { BtnSave. Attributes. Add ("onclick", "javascript: Save ();"); String [] strTxtValues = new string [2]; StrTxtValues [0] = dr ["1"]. ToString (); StrTxtValues [1] = dr ["2"]. ToString ();
String strValues = strTxtValues [0]; For (int I = 1; I <strTxtValues. Length; I ++) { StrValues + = "■" + strTxtValues [I]; } This.3.Value = strValues; } Private void SaveOrUpdate () // save and modify {
String [] strTxtValues = this.3.Value. Split ('■ '); String 1 = strTxtValues [0];
String 2 = strTxtValues [1]; } |