建了4个RadioButton,是一个组的(互斥)。另外有一个“清除”按钮,用来将第一个RadioButton选中。每个RadioButton的AutoPostBack属性设为true。4个RadioButton本身使用没有问题,但是不能被“清除”按钮设置为默认值(也就是第一个RadioButton),页面上显示的还是按“清除”按钮以前的RadioButton被选中)。代码如下:    protected void clearButton_Click(object sender, EventArgs e)
    {
        workerButton.Checked = true;
    }有趣的是,将code做如下修改,将另外3个设为false,就可以了。
    protected void clearButton_Click(object sender, EventArgs e)
    {
        bossButton.Checked = false;
        vpButton.Checked = false;
        presidentButton.Checked = false;
        workerButton.Checked = true;
    }而且,将设为false的code移在设为true的后面,也工作正常。各位老大,知道原因吗?谢谢。

解决方案 »

  1.   

    因为存在viewstate所以执行
     protected void clearButton_Click(object sender, EventArgs e)
        {
            workerButton.Checked = true;
        }
    之后选中的还是选中
      

  2.   

    这个的确是这样的,可能是viewstate导致的,但是
     protected void clearButton_Click(object sender, EventArgs e)
        {
            workerButton.Checked = true;
        }
    这样设置了后,在源里还是起作用的,只是因为后面已经有Checked的了,没有显示出来奇怪的是,如果Checked的在workerButton的前面,那么上面的代码就起作用了
    个人估计这是RadioButton在进行赋值时,如果查找到(这里是顺寻查找)Checked的,那么就可以改变该值,如果未查找到,那么就不能赋值
    写的比较乱,不过要是测试下就会发现这样的问题了
      

  3.   

    两位所言及是,谢谢。但是我把RadioButton的EnableViewState属性设为false,还是有此问题。看来没有彻底解决方法的话,只好用笨办法了。