Kashif
Kashif

Reputation: 14440

(ModalPopupExtender) two components with the same id can't be added to the application

I have a user control which I add on a page whenever user click on button. Following is the code to add 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 ModalPopupExtender popup. When I add 2nd control on page it throws an error internally which i can see in firebug. How to make this popup id 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 id 'mpeReply' can't be added to the application.

Upvotes: 6

Views: 10451

Answers (4)

David H
David H

Reputation: 21

Similar issue here. The solution for me was to change the Script Manager from a shortcut close tag to the full close tag , after adding the ScriptMode="Release" attribute:

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

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

Upvotes: 2

Tuyen Nguyen
Tuyen Nguyen

Reputation: 4479

I used this code to fix my problem, notice the ScriptMode is set to "Release"

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

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

Upvotes: 8

Thys
Thys

Reputation: 149

I have found the solution to this problem, as much as a lot of people have said, the simple solution is that your HTML is not properly formed - there is either an extra or missing closing tag to an element. Make sure that all your tags are properly closed and the problem should go away - struggled all day with this one!

Upvotes: 9

IUnknown
IUnknown

Reputation: 22468

Remove BehaviorID property from extender

Upvotes: 3

Related Questions