1

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>
Monika
  • 2,172
  • 15
  • 24
Gopi
  • 5,656
  • 22
  • 80
  • 146

3 Answers3

3

set autopostback=true for DropDownList ;

<asp:DropDownList class="custom" autopostback="true" ID="myid" runat="server" OnSelectedIndexChanged="change" OnTextChanged="change" onChange="myChange();">
Anand
  • 411
  • 3
  • 13
0

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');
}
Sajad Karuthedath
  • 14,987
  • 4
  • 32
  • 49
0

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

    }
Anand
  • 411
  • 3
  • 13