onChange and onSelectedIndexChanged events not firing - selectbox

限于喜欢 提交于 2019-12-13 02:56:10

问题


I was able to implement the selectbox but onchange and OnSelectedIndexChanged are not firing. Any insights?

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

回答1:


set autopostback=true for DropDownList ;

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



回答2:


i just copied your code and guess what it was working fine with AutoPostBack="True",first it shows alert message then twice event was getting fired for both event.i guess you must have implemented below snippet in your code behind file.

protected void change(object sender, EventArgs e)
    {

    }



回答3:


for the case of onChange add return to the javascript call

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

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


来源:https://stackoverflow.com/questions/19928665/onchange-and-onselectedindexchanged-events-not-firing-selectbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!