Finding controls on dynamically loaded usercontrol

2 posts, 0 answers
  1. Eric S.
    Eric S. avatar
    3 posts
    Member since:
    Oct 2009

    Posted 22 Oct 2009 Link to this post

    I have a modal window that loads a dynamic user control when the page is loaded. I am having trouble using the javascript getelementbyid to find the textboxes and labels on the dynamic user control. This is what I have so far:

    This is the page in the modal window that loads the user control dynamically.
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load 
            Dim modalusercontrol As Control = LoadControl("~/ModalUserControl.ascx") 
            modalusercontrol.ID = "modalusercontrol" 
        End Sub 

    In the page load of the User control I am trying to find the elementbyid and fill the values. ModalUserControl is the name of the user control that I am loading dynamically into the window.
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
            Dim updateParentScript As String = "function ConfigureDialog() { " & _ 
                            "var oWindow = GetRadWindow();    " & _ 
                            "var oArg = oWindow.Argument;    " & _ 
                            "var oArea =  document.getElementById('<%= (ModalUserControl.FindControl(""NewNameArea"")).ClientID %>').value;     " & _ 
                            "oArea.value = oArg.NameValue;  " & _ 
                            "var oArea =  document.getElementById('<%= (ModalUserControl.FindControl(""NewProfessionArea"")).ClientID %>').value;   " & _ 
                            "oArea.value = oArg.ProfessionValue;    " & _ 
                            "var oArea =  document.getElementById('<%= (ModalUserControl.FindControl(""NewLabelArea"")).ClientID %>').value;   " & _ 
                            "oArea.value = oArg.LabelValue;    " & _ 
                            "radWindow.Argument = arg;" & _ 
            Page.ClientScript.RegisterStartupScript(Me.[GetType](), "oWindow", updateParentScript, True) 
            Form1.Attributes.Add("onload", "ConfigureDialog()") 
        End Sub 

    Any help would be greatly appreciated. Thanks in advance.

  2. Fiko
    Fiko avatar
    1406 posts

    Posted 27 Oct 2009 Link to this post

    Hi Eric,

    I am not quite sure that I understood your scenario. You use an FORM tag in a user control with attribute runat="server". Please note, however, that a page cannot have two form tags with runat="server" attributes. This means that if you have a form tag with runat="server", in the ASPX page that hosts the user control, then the page will throw an error like : 'A page can have only one server-side Form tag.". The same error will appear if you declare two user controls, that contains form tag with attribute runat="server", on the same page. That is why, please open a new support ticket and send me your project, including a short description of the behavior that you need to achieve. I will check it and do my best to provide a working solution that will fit in your scenario.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top