|
こんな画面があって、 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem Value="1">1:ほげ</asp:ListItem>
<asp:ListItem Value="2">2:ほげほげ</asp:ListItem>
<asp:ListItem Value="3">3:ほげほげほげ</asp:ListItem>
<asp:ListItem Value="4">4:ほげほげほげほげ</asp:ListItem>
<asp:ListItem Value="5">5:ほげほげほげほげほげ</asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
javascript から AutoPostback に設定された DropDownList を変更したくなった。単純に $get("DoropDownList1").value = 1 とかしても、ドロップダウンリストの値は変わるけれどサーバ側にイベント伝わらない。 吐き出されたソースをみると DoropDownList の change イベントがこんな風になっていたので、 onchange="javascript:setTimeout('__doPostBack(\'DropDownList1\',\'\')', 0)" javascript 側をこうしてみる。 (function () { var dl = $get('DropDownList1'); dl.value=1;  eval(dl.onchange)(); })(); おぉ、動いた。w
|