Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(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.

like image 251
Kashif Avatar asked Nov 01 '12 21:11

Kashif


3 Answers

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!

like image 74
Thys Avatar answered Nov 04 '22 18:11

Thys


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

like image 39
Tuyen Nguyen Avatar answered Nov 04 '22 17:11

Tuyen Nguyen


Remove BehaviorID property from extender

like image 22
Yuriy Rozhovetskiy Avatar answered Nov 04 '22 18:11

Yuriy Rozhovetskiy