如何防止selectindexchange上的整页回发以获取下拉列表

            <asp:ImageButton ImageUrl="~/cies.png" runat="server" ID="btnShowDepend" OnCommand="btnShowDepend_Command" CommandName="TaskDepend" CommandArgument='' ToolTip="Click to view Dependencies" />         <%--  --%>  

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

ddlTaskName_onSelectIndexChanged函数:

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

使用上面的代码,只要在ddlTaskName更改索引,页面就会执行完全回发而不是仅部分(仅更新GridView)

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

想…我需要在两个单独的UpdatePanel中添加它们吗?

如果我取消注释triggersA control with ID 'ddlTaskName' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.出现以下错误: A control with ID 'ddlTaskName' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.

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

是因为这个:

 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标签吗? 如果你解开触发器,你需要在gridview周围放置asp:UpdatePanel

根据这篇文章看起来你的asp:Panel可能是ClientIDMode =“Static”的罪魁祸首。 尝试更改它,以便inheritance。

您需要在UpdatePanel标记中指定ChildrenAsTriggers="true" 。 您得到的错误是因为您的下拉列表实际上并不存在于标记中,这是Trigger行在compliation / runtime期间期望找到的内容 – 而是在动态添加它作为RowCreated函数中的RowCreated 。 如果您想尝试,可以在同一个函数中动态地向UpdatePanel添加触发器。