[英]Why is a control not found in an updatepanel
I have a button in a GridView inside an UpdatePanel. 我在UpdatePanel内的GridView中有一个按钮。
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. 我该如何解决该问题。
You better add your async trigger in the RowDataBound
event: 您最好在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);
}
}
}
Button btnShowDepend=(Button)TasksUpdatePanel.FindControl("btnShowDepend");
Please use this 请用这个
Or Maybe you have to put btnShowDepend out of updatepanel 或者也许您必须将btnShowDepend放在updatepanel中
Add one more updatepanel within ContentTemplate 在ContentTemplate中再添加一个updatepanel
<asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional"> <asp:ImageButton ID="btnShowDepend" runat="server" OnCommand="btnShowDepend_Command" /> </ContentTemplate>
you need to register that Image button as an AsyncPostbackTrigger. 您需要将该图像按钮注册为AsyncPostbackTrigger。
Try this one in RowDataBound
在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); } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.