2017-02-20 101 views
0

我的頁面有兩個控件,第二個的內容取決於第一個控件的下拉菜單。我有一個問題,因爲事件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 /呼叫-A-功能之前,頁面加載 –

回答

0

這將工作。請告訴我你想達到與下拉列表change事件處理什麼,可以幫助您在客戶端上回發之前做到這一點:

<%@ 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> 
相關問題