我已经在asp.net webforms中以编程方式创建了一堆html元素,并且在我的aspx页面上有一个UpdatePanel
。现在我想为每个创建的元素点击事件添加触发器。
这是我的代码
string content = "";
int i = 1000;
string btnRight = "";
string btnLeft = "";
GroupsRepository gr = new GroupsRepository();
List<Group> groups = new List<Group>();
groups = gr.LoadListAllGroups();
foreach (Group gp in groups)
{
btnLeft = "<button class='btnLeftService' runat='server' value='مقالات' />";
btnRight = "<button class='btnRightService' id='" + gp.GroupID.ToString() + "' runat='server' onserverclick='subGroups_ServerClick' value='زیر گروه ها' />";
content += "<div class='item'>";
content += "<div class='row m0 service '><div class='row m0 innerRow item'><div><i class='fa fa-laptop'></i><div class='serviceName'>" + gp.Title + "</div></div><div class='item-overlay left'><ul><li class='liLeft'>" + btnLeft + "</li><li class='liRight'>" + btnRight + "</li></ul></div></div></div>";
i++;
}
ourServises.InnerHtml = content;
GroupsRepository gr = new GroupsRepository();
List<Group> groups = new List<Group>();
groups = gr.LoadListAllGroups();
foreach (Group gp in groups)
{
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = gp.GroupID.ToString();
trigger.EventName = "Click";
updatepanel2.Triggers.Add(trigger);
}
但在运行时,我收到此错误:
ID为&#39; 1&#39;在UpdatePanel&quot; updatepanel2&#39;。
中找不到触发器
我该怎么办?