简体   繁体   English

如何使用UpdatePanel触发没有任何回发的“选定索引已更改”事件?

[英]How can I fire Selected Index Changed event without any postback using UpdatePanel?

I have a SignIn page that has a SignInUserControl page and is inside a MasterPage. 我有一个SignIn页面,该页面具有一个SignInUserControl页面,并且位于MasterPage内。 Inside the SignIn page I have 2 drop down lists 在“登录”页面中,我有2个下拉列表

ddlCountry ddlCountry

ddlCity ddlCity

I want to change the country and it automaticly load the cities. 我想更改国家,并自动加载城市。 Using this code: 使用此代码:

 <li>
    <label>Your Country:</label>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:DropDownList ID="ddlCountry" runat="server" Width="356px"
                DataTextField="Country" DataValueField="CodCountry"
                OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" AutoPostBack="true" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel>
</li>
<li>
    <label>Your City:</label>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:DropDownList ID="ddlGestor" runat="server" Width="356px" DataTextField="City" DataValueField="CodCity" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel>
</li>

the cities get loaded but AutoPostBack="True" calls the SignIn Page_Load(), the MasterPage Page_Load() and the SignInUserControl Page_Load(). 城市已加载,但是AutoPostBack =“ True”调用SignIn Page_Load(),MasterPage Page_Load()和SignInUserControl Page_Load()。 And by the way I have other functions inside these Page_Load(), so they are also being called 顺便说一下,我在这些Page_Load()中还有其他函数,因此它们也被称为

Is there any way to avoid this? 有什么办法可以避免这种情况? It seems like UpdatePanel is not a real Ajax because to work it has to send to the server all those pages and not only the block of code that I want 看来UpdatePanel不是真正的Ajax,因为要工作,它必须将所有这些页面发送到服务器,而不仅仅是我想要的代码块

yes you can achive it by using ajax cascading drop -down 是的,您可以使用Ajax级联下拉菜单来实现

by using it you can achive the binding without any postback firing up 通过使用它,您可以实现绑定而无需任何回发

follow up this link 跟进此链接

http://www.ajaxcontroltoolkit.com/CascadingDropDown/CascadingDropDown.aspx http://www.ajaxcontroltoolkit.com/CascadingDropDown/CascadingDropDown.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用javascript获取updatepanel中的回发元素? - How to get postback element in updatepanel using javascript? 当文本框更改但用户未更改时,如何触发 Javascript 事件? - How can I fire a Javascript event when a text box is changed but not by the user? 如何在属性更改后立即触发属性更改事件? - How can I fire the property change event immediately after the property is changed? 如何在 React Native 中使用 onLongPress 触发事件? - How can I fire an event using onLongPress in React native? 使用JavaScript更改值时如何触发TextBox更改事件? - How to fire TextBox change event when value is changed using javascript? 单击整行的任何部分时,触发网格视图的选定索引更改事件 - Fire a selected Index change event of a grid view on clicking any portion of a whole row 如何从Gridview中的LinkBut​​ton触发Onclick事件驻留在updatePanel中? - How to fire Onclick event from LinkButton in Gridview resides in updatePanel? 我怎么能在这里举办popstate活动? - How can i fire popstate event here? 如何在JavaScript中触发touchcancel事件? - How can I fire touchcancel event in javascript? 如何在选项标签中触发事件? - How can I fire an event in an option tag?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM