onChange和SelectedIndexChanged事件未触发 - 选择框

时间:2013-11-12 12:04:28

标签: c# asp.net events onchange drop-down-menu

我能够实现选择框但是onchange和SelectedIndexChanged没有触发。任何见解?

<div class="hasJS">
<asp:DropDownList class="custom" ID="myid" runat="server" OnSelectedIndexChanged="change" OnTextChanged="change" onChange="myChange();">
<asp:ListItem>Hello</asp:ListItem>
<asp:ListItem>Hello1</asp:ListItem>
<asp:ListItem>Hello3</asp:ListItem>
<asp:ListItem>Hello4</asp:ListItem>
<asp:ListItem>Hello5</asp:ListItem>
<asp:ListItem>Hello6</asp:ListItem>
<asp:ListItem>Hello7</asp:ListItem>
<asp:ListItem>Hello8</asp:ListItem>
</asp:DropDownList>
</div>

 <script type="text/javascript">

   $(function () {

       $("select.custom").each(function () {
           var sb = new SelectBox({
               selectbox: $(this),
               height: 150,
               width: 200
           });
       });

   });

   function myChange() {
       alert("Hai");
   }

    </script>

3 个答案:

答案 0 :(得分:2)

为DropDownList设置autopostback = true;

<asp:DropDownList class="custom" autopostback="true" ID="myid" runat="server" OnSelectedIndexChanged="change" OnTextChanged="change" onChange="myChange();">

答案 1 :(得分:0)

对于onChange的情况添加返回到javascript调用

     <asp:DropDownList ID="cbProduct" runat="server" 
                                        CssClass="common_transaction_textbox_style" onchange="return LoadProductBatchByName();" Height="23px" Width="200px">
                                    </asp:DropDownList>

 function LoadProductBatchByName() {
{
          alert('test');
}

答案 2 :(得分:0)

我刚刚复制了你的代码并猜测它与AutoPostBack =“True”的工作正常,首先它显示了警告消息,然后两次事件都被触发了两个event.i猜你必须在代码隐藏文件后面的代码片段中实现

protected void change(object sender, EventArgs e)
    {

    }