asp.net页面中使用了<input name="txt" >控件。如何在后端的c#代码中取道这个控件得值?
如题!
asp.net页面中使用了 <input name= "txt " > 控件。如何在后端的c#代码中取道这个控件得值?
在线等,大家帮帮忙
[解决办法]
大致原理如下:
<script language= "javascript ">
function function1
{
document.getElementById( " <%= divTemp.ClientID %> ").value = document.getElementById( "txt ").value;
}
</script>
<body>
<input name= "txt " id= "txt ">
<div runat= "server " id = "divTemp "/>
<asp:Button id= "Button1 "/>
<script language= "c# " runat= "server ">
protected Page_Load()
{
this.Button1.Arributes.Add( "onclick " , "function1() ");
}
protected Button1_Click
{
string strValue = divTemp.Text;
}
</script>
[解决办法]
更正一处:
protected Button1_Click
{
string strValue = divTemp.Text;
}
应该为
protected Button1_Click()
{
string strValue = divTemp.Text;
}
[解决办法]
要给一个Id属性和值( <input id= "txt " runat= "server "> </input> )
在HTML控件上,右键转为服务器控件,然后在后台cs文件的声明部分,可以看到该控件的声明.
[解决办法]
为什么不这样:
<input name= "txt " id= "txt " runat= "server ">
然后在后台直接这样取值
txt.Value