在.NET中我写了一个javascript给label赋值,但在服务器端获不到值
<script language= "javascript ">
function RadClick()
{
if(document.Form1.Aregg1.checked)
{
document.all.LabAccIdeaState1.innerText = "1 ";
return;
}
if(document.Form1.ArgeeNo1.checked)
{
document.all.LabAccIdeaState1.innerText = "2 ";
return;
}
}
</script>
<form id= "Form1 " name= "Form1 " method= "post " runat= "server ">
<input id=Argee1 onclick=RadClick() type=radio value=1 name=Aregg1 checked> 同意
<input id=ArgeeNo1 onClick() type=radio value=2 name=Aregg1> 不同意
<input type=button value= "添加 " runat=server id=ButAdd>
</form>
为什么我在点不同意后,在界面上javascript 是给label赋值为2,但我在.net后面获不到值???不知道为什么,请大家帮我看看!!!
------解决方案--------------------服务器端是放在ViewState里的,js不能操作ViewState,所以不行
呢可以放在隐藏表单里面
------解决方案--------------------你这样是取不到的,要么做为参数传,要么放到隐藏域里然后再取
------解决方案-------------------- <script language= "javascript ">
function RadClick()
{
if(document.Form1.Aregg1.checked)
{
document.all.LabAccIdeaState1.innerText = "1 ";
document.all.hdnVal.innerText = "1 ";
return;
}
if(document.Form1.ArgeeNo1.checked)
{
document.all.LabAccIdeaState1.innerText = "2 ";
document.all.hdnVal.innerText = "1 ";
return;
}
}
</script>
<form id= "Form1 " name= "Form1 " method= "post " runat= "server ">
<input id=Argee1 onclick=RadClick() type=radio value=1 name=Aregg1 checked> 同意
<input id=ArgeeNo1 onClick() type=radio value=2 name=Aregg1> 不同意
<input type=button value= "添加 " runat=server id=ButAdd>
<input type= "hidden " value= " " runat= "server " id= "hdnVal " >
</form>
.cs中
string val = hdnVal.value;