(ModalPopupExtender) two components with the same identifier cannot be added to the application

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.

+4
source share
4 answers

Remove the BehaviorID property from the expander

+1
source

I used this code to fix my problem, note that ScriptMode is set to "Release"

 <AjaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release"> </AjaxControlToolkit:ToolkitScriptManager> 

I see a similar answer at this link: http://www.advancesharp.com/questions/17658/sys-invalidoperationexception-two-components-with-the-same-id-xxx-can-t-be-added-to- the-application

+8
source

I found a solution to this problem, like many people, a simple solution is that your HTML is not correctly formed - there is either an additional or missing closing tag for the element. Make sure all your tags are closed correctly and the problem should go away - fight it all day!

+6
source

A similar question is here. The solution for me was to change the Script manager from the close label of the shortcut to the full close tag by adding the ScriptMode = "Release" attribute:

Edit: <asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server" />

so that: <asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server></asp:ScriptManager>

+2
source

Source: https://habr.com/ru/post/1443537/


All Articles