asp.net a solution to save and modify control values without the runat=server control
- 2020-05-16 06:39:22
- OfStack
js:
function Save()// Saves a value that is not a server-side control
{
var 1= document.getElementById('1Box').value;
var 2 = document.getElementById('2Box').value;
var TxtValue = 1 + " s " + 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(' s ');
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:
void LoadData()// Page load
{
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 += " s " + strTxtValues[i];
}
this.3.Value = strValues;
}
private void SaveOrUpdate()// Save, modify
{
string[] strTxtValues = this.3.Value.Split(' s ');
string 1= strTxtValues[0];
string 2= strTxtValues[1];