我在UpdatePanel内的GridView中有一个按钮。
运行页面时出现以下错误:
A control with ID 'btnShowDepend' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.
如何解决此问题。
答案 0 :(得分:2)
您最好在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);
}
}
}
答案 1 :(得分:2)
Button btnShowDepend=(Button)TasksUpdatePanel.FindControl("btnShowDepend");
请使用此
或许你必须把btnShowDepend从updatepanel中删除
答案 2 :(得分:2)
在 ContentTemplate 中再添加一个更新面板
<asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional">
<asp:ImageButton ID="btnShowDepend" runat="server" OnCommand="btnShowDepend_Command" />
</ContentTemplate>
答案 3 :(得分:2)
您需要将图片按钮注册为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);
}
}