页面里有
<input name= "main_1 " class= "Html_001_a3 " type= "text ">
<input name= "main_2 " class= "Html_001_a3 " type= "text ">
<input name= "main_N " class= "Html_001_a3 " type= "text ">
如何点击 按钮后给main_N的VALUE添加内容。
按钮是runat= "server "的。所以必须在C#里写。
for (int i = 0; i < 20; i++)
{
if (Request.Form[ "main_ " + i] != null)
{
//Response.Write[ "main_ " + i] = //ds.Tables[0].Rows[0][n].ToString();
}
}
上面是错误的。如何实现?
------解决方案--------------------------------------------------------
大概如下
for (int i = 1; i < 20; i++)
{
string sId = "main_ " + i.ToString();
//Response.Write[ "main_ " + i] = //ds.Tables[0].Rows[0][n].ToString();
ClientScript.RegisterStartupScript(this.GetType(), "t1 ", " <script> if(document.all[ ' " + sId + " ']==null){} else {document.all[ ' " + sId + " '].value = 'a ' ;)} </script> ");
}
------解决方案--------------------------------------------------------
如果是runat= "server "的直接通过id就可以访问如果不是. <input name= "main_1 " class= "Html_001_a3 " <%=GetValue(1)%> type= "text "> 在后台写GetValue返回值.
------解决方案--------------------------------------------------------
搞这么复杂。下面办法直接就OK
<input name= "main_N " class= "Html_001_a3 " type= "text " Value= " <%=value%> ">
//这里加上Value= " <%=value%> ",意识是从服务端取一个值在这里输出。
然后在ASPX.CS文件里的BUTTON_CLICK事件里写下面代码
value = "Hello! "
需要注意的是,value 须在aspx.cs中声明为PUBLIC