SearchForKnowledge
SearchForKnowledge

Reputation: 3751

Why is a control not found in an updatepanel

I have a button in a GridView inside an UpdatePanel.

I get the following error when I run the page:

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

How do I resolve the issue.

Upvotes: 1

Views: 789

Answers (4)

dario
dario

Reputation: 5269

You better add your async trigger in the RowDataBound event:

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

Upvotes: 2

Balaji
Balaji

Reputation: 1515

you need to register that Image button as an AsyncPostbackTrigger.

Try this one in 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);  
  }  
}

 

Upvotes: 2

Balaji
Balaji

Reputation: 1515

Add one more updatepanel within ContentTemplate

		<asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional">
  <asp:ImageButton ID="btnShowDepend" runat="server" OnCommand="btnShowDepend_Command" />
</ContentTemplate>

Upvotes: 2

ruken aslan
ruken aslan

Reputation: 69

Button btnShowDepend=(Button)TasksUpdatePanel.FindControl("btnShowDepend");

Please use this

Or Maybe you have to put btnShowDepend out of updatepanel

Upvotes: 2

Related Questions