在页面里
<script>
function()
{
    if(Form1.RadioButton2.checked){
         Form1.TextBox1.value="0";
    } else {
 Form1.TextBox1.value="1";
    }
}
</script>
服务器端
RadioButton1.Attributes.Add("OnCheckedChanged","f()");
为什么这段代码并不运行哪?

解决方案 »

  1.   

    <script>
    function f()
    {
        if(Form1.RadioButton2.checked){
             Form1.TextBox1.value="0";
        } else {
     Form1.TextBox1.value="1";
        }
    }
    </script>
    服务器端
    RadioButton1.Attributes.Add("onclick","f()");
      

  2.   

    用onclick
    错误:对象不支持此属性或方法!用OnCheckedChanged则没有错误,但是也无法运行
      

  3.   

    RadioButton1.Attributes.Add("onclick","f()");这样没错!自己看一下html源代码
      

  4.   

    function()
    {
        if(Form1.RadioButton2.checked){
             Form1.TextBox1.value="0";
        } else {
     Form1.TextBox1.value="1";
        }
    }
    </script>你的f()好像掉了啊。
      

  5.   

    <script>
    function test()
    {
    var d=document.getElementById("RadioButton2");
    var s=document.getElementById("TextBox1");
    if(d.checked)
    {
    s.value="0";
    }
    else
    {
    s.value="1";
    }
    }
    </script>
    服务器端
    RadioButton1.Attributes.Add("onclick","test()");
      

  6.   

    检查你的RadioButton1控件,如果是webcontrol,那么使用RadioButton1.Attributes.Add("onclick","test()");,onclick事件不是在<input type="radio" onclick="f();" >,而是在其他的Tag上,好像是Span/Div, 你看看客户端生成的html就知道了。
      

  7.   

    你的控件是RadioButtonList还是RadioButton?
      

  8.   

    我的控件是两个RadioButton,只是在一个组内