2017-02-20 13 views
0

マイページには2つのコントロールがあり、第2のコントロールの内容は最初のドロップダウンに応じて異なります。 SelectedIndexChangeイベントがポストバックの後にトリガーされるため、問題が発生します。ポストバックの前にSelectedIndexChangeをトリガーする方法は?

更新パネルとトリガーを試しましたが、動作しません。

<asp:ScriptManager ID="ScriptManager1" runat="server" /> 

<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="true" CssClass="form-control" 
      OnSelectedIndexChanged="ddlTest_SelectedIndexChanged" /> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="ddlTest" EventName="SelectedIndexChanged" /> 
    </Triggers> 
</asp:UpdatePanel> 

ポストバックの前にイベント「SelectedIndexChange」を強制する考えですか?

+1

を多分これがお手伝いします。http://stackoverflow.com/questions/ 1364346/calling-a-function-before-page-load –

答えて

0

これは動作します。ドロップダウンリスト変更イベントハンドラを達成したいとあなたがクライアント上でポストバックする前にそれを行うことができます何を教えてください:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx.cs" Inherits="WebApplication4.WebForm11" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script src="Scripts/jquery-1.9.1.min.js"></script> 
    <script type="text/javascript"> 
     $(function() { 
      $("#ddlTest").change(function() { 
       alert($("#ddlTest option:selected").text()); 
       alert($("#ddlTest option:selected").val()); 
      }) 
     }) 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:DropDownList runat="server" ID="ddlTest" > 
      <asp:ListItem Text="aText" Value="aValue" /> 
      <asp:ListItem Text="bText" Value="bValue" /> 
      </asp:DropDownList> 
    </div> 
    </form> 
</body> 
</html> 
関連する問題