如何防止下拉列表的 selectedindexchange 上的整页回发 [英] How to prevent full page postback on selectedindexchange for dropdownlist

查看:17
本文介绍了如何防止下拉列表的 selectedindexchange 上的整页回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="TasksUpdatePanel" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="pnlDropDown" runat="server" ClientIDMode="Static" CssClass="pnlDropDown">
            <!-- TASK NAME -->
            <asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>

        </asp:Panel>
        <asp:GridView ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="You currently have no tasks assigned to you" OnRowDataBound="yourTasksGV_RowDataBound" OnRowCreated="yourTasksGV_RowCreated">
            <Columns>
                <asp:TemplateField HeaderStyle-Width="2%">
                    <ItemTemplate>
                        <asp:ImageButton ImageUrl="~/cies.png" runat="server" ID="btnShowDepend" OnCommand="btnShowDepend_Command" CommandName="TaskDepend" CommandArgument='<%#Eval("TestIt") %>' ToolTip="Click to view Dependencies" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:HyperLinkField HeaderStyle-Width="16%" Target="_self" DataNavigateUrlFields="Task Detail" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Detail" SortExpression="Task Name" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField HeaderStyle-Width="10%" DataField="Workgroup" HeaderText="Workgroup" SortExpression="Workgroup" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField HeaderStyle-Width="7%" DataField="Status" HeaderText="Status" SortExpression="Status" ItemStyle-CssClass="taskTableColumn" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
    <%--<Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlTaskName" EventName="onSelectIndexChanged" />
    </Triggers>--%>
</asp:UpdatePanel>

每当 ddlTask​​Name_onSelectIndexChanged 函数被执行时,都会有一个完整的页面回发,而不仅仅是更新 UpdatePanel

Whenever the ddlTaskName_onSelectIndexChanged function is executed there is a full page postback rather than just updating the UpdatePanel

ddlTask​​Name_onSelectIndexChanged 函数:

protected void ddlTaskName_onSelectIndexChanged(object sender, EventArgs e)
{
    PullData(ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString(), false); //calls a function to update the GridView
}

使用上述代码,每当 ddlTask​​Name

我可以添加/修改哪些代码以确保不执行完整的回发,并且仅在索引更改时更新 GridView.

What code can I add/modify to ensure the full postback isn't executed and only update the GridView on index changed.

想...我需要将它们添加到两个单独的 UpdatePanel 中吗?

Thought... Do I need to add them in two separate UpdatePanel?

如果我取消对 triggers 的注释,我会收到以下错误:在 UpdatePanel 'TasksUpdatePanel' 中找不到触发器 ID 为 'ddlTask​​Name' 的控件.

If I uncomment the triggers, I get the following error: A control with ID 'ddlTaskName' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.

我将下拉列表附加到 Gridview,如下所示:

I am attaching the dropdownlist to the Gridview like this:

是不是因为这个:

protected void yourTasksGV_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        GridView hGrid = (GridView)sender;
        GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

        TableHeaderCell tcCellTask = new TableHeaderCell();
        tcCellTask.Controls.Add(ddlTaskName);
        gvrRow.Cells.Add(tcCellTask);

        yourTasksGV.Controls[0].Controls.AddAt(0, gvrRow);
    }
}

推荐答案

您的代码看起来不错.您是否尝试注释掉 asp:Panel 选项卡?如果您取消注释触发器,则需要将 asp:UpdatePanel 放在 gridview 周围

your code seems fine. did you try to comment out asp:Panel tab? if you unccoment triggers, you need to put asp:UpdatePanel around gridview

这篇关于如何防止下拉列表的 selectedindexchange 上的整页回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆