1

選択ボックスを実装できましたが、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>
4

3 に答える 3

3

DropDownList に autopostback=true を設定します。

<asp:DropDownList class="custom" autopostback="true" ID="myid" runat="server" OnSelectedIndexChanged="change" OnTextChanged="change" onChange="myChange();">
于 2013-11-12T12:05:19.057 に答える
0

コードをコピーしたところ、AutoPostBack="True" で正常に動作していたことを推測しました。最初に警告メッセージが表示され、次に両方のイベントで 2 回イベントが発生しました。コード ビハインド ファイルに以下のスニペットを実装したに違いないと思います。

protected void change(object sender, EventArgs e)
    {

    }
于 2013-11-13T03:42:30.573 に答える
0

onChange の場合は、javascript 呼び出しに return を追加します

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

 function LoadProductBatchByName() {
{
          alert('test');
}
于 2013-11-12T12:10:18.913 に答える