为什么在更新面板中找不到控件
本文关键字:找不到 控件 更新 为什么 | 更新日期: 2023-09-27 17:50:19
我在GridView中有一个按钮。
当我运行页面时,我得到以下错误:
A control with ID 'btnShowDepend' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.
如何解决这个问题
Button btnShowDepend=(Button)TasksUpdatePanel.FindControl("btnShowDepend");
请使用
或者你可以把btnShowDepend放在updatepanel
在ContentTemplate中再添加一个updatepanel
<asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional">
<asp:ImageButton ID="btnShowDepend" runat="server" OnCommand="btnShowDepend_Command" />
</ContentTemplate>
你需要注册图像按钮作为AsyncPostbackTrigger
试试RowDataBound
protected void yourTasksGV_RowDataBound(object sender, GridViewRowEventArgs
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton ib = e.Row.FindControl("btnShowDepend") as ImageButton;
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(ib);
}
}
你最好在RowDataBound
事件中添加异步触发器:
void yourTasksGV_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton ib = e.Row.FindControl("btnShowDepend") as ImageButton;
if (ib != null)
{
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = ib.UniqueID;
trigger.EventName = "Click";
TasksUpdatePanel.Triggers.Add(trigger);
}
}
}