2017-02-20 88 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>