【问题标题】:onChange and onSelectedIndexChanged events not firing - selectboxonChange 和 onSelectedIndexChanged 事件未触发 - 选择框
【发布时间】:2013-11-12 12:04:28
【问题描述】:

我能够实现选择框,但 onchange 和 OnSelectedIndexChanged 没有触发。有什么见解吗?

<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>

【问题讨论】:

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


    【解决方案1】:

    为 DropDownList 设置 autopostback=true ;

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

    【讨论】:

    • 抱歉没用!
    【解决方案2】:

    我刚刚复制了您的代码并猜测它在 AutoPostBack="True" 下工作正常,首先它显示警报消息,然后两次事件都被两个事件触发。我猜您必须在代码中实现低于 sn-p隐藏文件。

    protected void change(object sender, EventArgs e)
        {
    
        }
    

    【讨论】:

      【解决方案3】:

      对于 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');
      }
      

      【讨论】:

      • 抱歉没用!
      • 我已经编辑了我的代码并将 onChange 更改为 onchange..!!它会工作只是检查..!!
      猜你喜欢
      • 2011-08-07
      • 2012-08-25
      • 2015-08-09
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 2011-08-17
      • 2012-12-13
      • 1970-01-01
      相关资源
      最近更新 更多