为什么在updatepanel中找不到控件

时间:2015-05-21 12:40:31

标签: c# asp.net updatepanel

我在UpdatePanel内的GridView中有一个按钮。

运行页面时出现以下错误:

A control with ID 'btnShowDepend' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.

如何解决此问题。

4 个答案:

答案 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);  
  }  
}