防止 CascadingDropDown 进行初始 AJAX 调用

发布于 2024-08-07 17:51:15 字数 47 浏览 2 评论 0原文

我将在服务器端预先填充我的下拉列表。我只希望在父控件发生更改时触发级联下拉列表。

I'm going to pre-populate my drop down lists on the server side. I only want the cascading drop-down to fire if the parent control changes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你曾走过我的故事 2024-08-14 17:51:15

从代码隐藏中填充父列表框,并将其“autopostback”属性设置为 true。设置 OnSelectedIndexChanged="PopulateChildListBox"

将子 ListBox 放入 UpdatePanel 中,并将 ParentListBox 与 Updatepanel 关联

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="lbParent" />
        </Triggers>
        <ContentTemplate>
            <asp:ListBox ID="lbChild" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>

在您的代码隐藏中,让“PopulateChildListBox”方法填充子 ListBox

protected void PopulateChildListBox(object sender, EventArgs e)
{
    // Get the data for the child listbox
    lbChildListBox.DataBind();
}

因此,仅您的子列表框当父列表框更改时,会更新其内容(通过 Asp.Net AJAX)。

Populate your parent ListBox from the code-behind, and set its "autopostback" attribute to true. Set OnSelectedIndexChanged="PopulateChildListBox"

Put the child ListBox in an UpdatePanel, and associate the parentListBox with the Updatepanel

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="lbParent" />
        </Triggers>
        <ContentTemplate>
            <asp:ListBox ID="lbChild" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>

In your code-behind, have the "PopulateChildListBox" method fill the child ListBox

protected void PopulateChildListBox(object sender, EventArgs e)
{
    // Get the data for the child listbox
    lbChildListBox.DataBind();
}

So, your child listbox only ever updates its content (via Asp.Net AJAX) when the parent ListBox changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文