This is a migrated thread and some comments may be shown as answers.

Finding controls on dynamically loaded usercontrol

1 Answer 169 Views
Window
This is a migrated thread and some comments may be shown as answers.
Eric S.
Top achievements
Rank 1
Eric S. asked on 22 Oct 2009, 02:20 PM
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" 
        Ph1.Controls.Add(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.
-Eric


1 Answer, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 27 Oct 2009, 06:04 PM
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.

Greetings,
Fiko
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.
Tags
Window
Asked by
Eric S.
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Share this question
or