Web User Control and wijmo:C1ComboBox

Posted by: michaelwhite on 10 September 2017, 11:47 am EST

  • Posted 10 September 2017, 11:47 am EST

    Hi Component One

    I have created a new Web User Control for my application that consists of numerous wijmo:C1ComboBox each with a id e.g


    etc for a week

    My issue is when I add this control to the main web form multiple times lets say 5 times.

    I am adding the controls using the following code

    For Each p In userlist
    Dim timecontrole As New TimeSelector

    panel.Controls.Add(New LiteralControl("<asp:panel runat=" & "server" & ">"))
    panel.Controls.Add(New LiteralControl("<asp:Updatepanel runat=" & "server" & ">"))
    panel.Controls.Add(DirectCast(Page.LoadControl("~/Controls/TimeSelector.ascx"), UserControl))

    panel.Controls.Add(New LiteralControl("</asp:UpdatePanel>"))
    panel.Controls.Add(New LiteralControl("</asp:Panel>"))

    panel.Controls.Add(New LiteralControl("<p></p>"))


    Each ComboBox has code for on selected index changed in the code behind. My form has an issue with having multiple controls with the same ID.

    This is my first real ASP.Net project so I am struggling a little to understand if I am taking the right approach to adding a control multiple times to the web form.

    Any advice or Guidence would be great


  • Replied 10 September 2017, 11:47 am EST

    Hi Michael,

    The issue occurs because you haven't assigned any IDs to the UserControls before adding them to the page. Because of this, multiple Usercontrols have same IDs and you get the error.

    Please see the code below :

    protected void Page_Load(object sender, EventArgs e)
    int j = 0;

    for (int i = 0; i < 3; i++)
    WebUserControl1 uc1 = new WebUserControl1();

    Panel1.Controls.Add(new LiteralControl("<asp:panel1 runat=" + "server" + ">"));
    Panel1.Controls.Add(new LiteralControl("<asp:Updatepanel1 runat=" + "server" + ">"));
    uc1 = (WebUserControl1)Page.LoadControl("~/WebUserControl1.ascx");
    uc1.ID = "UC" + j;
    Panel1.Controls.Add(new LiteralControl("</asp:Updatepanel1>"));
    Panel1.Controls.Add(new LiteralControl("</asp:panel1>"));
    Panel1.Controls.Add(new LiteralControl("<p></p>"));
    j += 1;

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels