在asp.net 2.0中,页面page中设置了autoeventwireup="true"页面上有一个RadioButtonList:<asp:RadioButtonList ID="rblChoice" runat="server" RepeatDirection="horizontal" AutoPostBack="True" OnSelectedIndexChanged="rblChoice_SelectedIndexChanged">此时OnSelectedIndexChanged事件是已经绑定,而且好使的但是我需要在代码中进行判断,比如            if (_strState.Equals("take"))
            {
                rblChoice.OnSelectedIndexChanged -= new Event(rblChoice_SelectedIndexChanged);
            }但是这样做并不好使,事件绑定依然有效。请问我应该怎么做才能取消掉这个事件绑定? 谢谢!

解决方案 »

  1.   

    设置autoeventwireup="false"当然可以,但是这样做之后如何在需要事件绑定的时候使事件绑定生效? 在override void On_Init()中可以做到this.OnLoad += new EventHandler(Page_Load),但是无法应用判断:
    if (_strState.Equals("take"))
                {
                    rblChoice.OnSelectedIndexChanged += new Event(rblChoice_SelectedIndexChanged);
                }
    因为这时_strState根本没有值!而把这一段判断写在别的地方,又根本不生效了,继续请教!在asp.net 2.0中事件绑定的注册只能在On_Init()里面进行么?
    谢谢!