簡體   English   中英

回發前如何觸發SelectedIndexChange?

[英]How to trigger SelectedIndexChange before postback?

我的頁面有兩個控件,第二個控件的內容取決於第一個控件的下拉菜單。 我有一個問題,因為回發后觸發了事件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”嗎?

這將起作用。 請告訴我您要使用下拉列表更改事件處理程序實現的目標,並可以在客戶端回發之前幫助您完成此操作:

<%@ 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM