I have a user control that I add to the page whenever the user clicks a button. Below is the code to add the control.
protected void Page_Init(object sender, EventArgs e) { if (Session["ControlCount"] != null) { for (int i = 1; i <= (int)Session["ControlCount"]; i++) { Control myUserControl = LoadControl("~/Controls/MessageControl.ascx"); divMessageControl.Controls.Add(myUserControl); } } } protected void Page_Load(object sender, EventArgs e) { } protected void btnExpand_Click(object sender, EventArgs e) { int count = 0; if (Session["ControlCount"] != null) { count = Convert.ToInt32(Session["ControlCount"]); } Control myUserControl = (Control)Page.LoadControl("~/Controls/MessageControl.ascx"); divMessageControl.Controls.Add(myUserControl); Session["ControlCount"] = count + 1; }
This control has a ModalPopupExtender popup. When I add a second control to the page, it throws an internal error that I see in firebug. How to make this unique identifier unique?
<asp:ModalPopupExtender ID="mpeReply" BehaviorID="mpeReply" runat="server" TargetControlID="btnReply" PopupControlID="pnlReply" BackgroundCssClass="ModalPopupBG1"> </asp:ModalPopupExtender>
Sys.InvalidOperationException: Sys.InvalidOperationException: two components with the same identifier 'mpeReply' cannot be added to the application.
source share