<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnChange="return check();" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList>
问题说明:
OnChange="return check();" 事件执行后,不管返回false还是true,OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> 事件都不再执行,如果写成OnChange="check();"那么不管返回什么都可以执行OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> 事件,现在我既要写成OnChange="return check();" 而且又要执行OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> 事件,怎么改?

解决方案 »

  1.   

    DropDownList1.Attribute.Add("onchange","return check();");
      

  2.   

    务器控件的服务器事件一般对应到客户端控件的相应事件,如Dropdownlist的SelectedIndexChanged事件对应HTML <Select>的onchange事件。如果要手工增加一个onchange事件,则会在客户端产生两个onchange,浏览器就会忽略掉一个
    string str= Page.GetPostBackClientHyperlink(btn, "");
    Dropdownlist1.Attributes.Add("onchange", "test(\"" + str+ "\")");
    function test(cmd){
    if confirm("")
    eval(cmd);
    }
      

  3.   

    一般DropDownList调用js用onclick就可以了!
      

  4.   

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnClick="return check();" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            </asp:DropDownList>这样写也不行
      

  5.   

    去掉OnSelectedIndexChanged事件和autopostback=true
    把事件里的代码抽到一个隐藏的button的click事件里
    在onchange的js返回true时,用document.getelementbyid找到button,然后让button click