用javascript给label赋值,然后服务器端获取
我用的是VS2003,没有服务器端的隐藏域控件,还有什么解决方案?
最好能有简单代码说明我已经用这样的代码试过了 不行的
<script language="javascript">
function GetIt()
{
document.getElementById("label1").innerHTML = "WebCtrl";
document.getElementById("hdnVal").innerHTML = "WebCtrl";
}
</script>
<form id="Form1 " name="Form1 " method="post" runat="server ">
<asp:Label id="Label1" runat="server">Label</asp:Label>
<INPUT type="button" value="htmlBtn" onclick="GetIt()">
<asp:Button id="btnShow" runat="server" Text="WebBtn"></asp:Button>
<INPUT type="hidden" id="hdnVal" runat="server">
</form>服务端
private void btnShow_Click(object sender, System.EventArgs e)
{
string val = hdnVal.value;
Response.Write(val);
}
我用的是VS2003,没有服务器端的隐藏域控件,还有什么解决方案?
最好能有简单代码说明我已经用这样的代码试过了 不行的
<script language="javascript">
function GetIt()
{
document.getElementById("label1").innerHTML = "WebCtrl";
document.getElementById("hdnVal").innerHTML = "WebCtrl";
}
</script>
<form id="Form1 " name="Form1 " method="post" runat="server ">
<asp:Label id="Label1" runat="server">Label</asp:Label>
<INPUT type="button" value="htmlBtn" onclick="GetIt()">
<asp:Button id="btnShow" runat="server" Text="WebBtn"></asp:Button>
<INPUT type="hidden" id="hdnVal" runat="server">
</form>服务端
private void btnShow_Click(object sender, System.EventArgs e)
{
string val = hdnVal.value;
Response.Write(val);
}
function GetIt()
{
document.getElementById("Label1").innerText = "WebCtrl";
document.getElementById("hdnVal").value = "WebCtrl";
}
</script> <asp:Label id="Label1" runat="server">Label </asp:Label>
<input type="button" value="htmlBtn" onclick="GetIt()"> <asp:Button id="btnShow" runat="server" Text="WebBtn" onclick="btnShow_Click"> </asp:Button>
<input type="hidden" id="hdnVal" runat="server">
后台C#代码,卸载了你那个按钮btnShow的点击事件里面 protected void btnShow_Click(object sender, EventArgs e)
{
Response.Write(Request.Form["hdnVal"].ToString());
}测试了一下,能取到hidden的值
=》<INPUT type="hidden" id="hidID" name='hidName'> 赋值<script language="javascript">
function GetIt()
{
document.getElementById("hidID").value= "WebCtrl";
}
</script>
取值的时候Label1.Text=Request.Form["hidName"];