Seting Properties of Dynamic Controls

Results 1 to 2 of 2

Thread: Seting Properties of Dynamic Controls

  1. #1
    Join Date
    Dec 1969

    Default Seting Properties of Dynamic Controls

    I am fairly new to use of dynamic user controls... and am thinking I am missing something obvious with this. <BR><BR>I have a series of user controls that may or may not be displayed, depending on the state of other variables set throughout the application. <BR><BR>I am using the following method to dynamically add a user control to the page: <BR><BR>Dim uclMyControl As New MyProject.MyControlClass <BR>uclMyControl.prpSetAValue = "Some Value" <BR>uclMyControl.Visible = True <BR>Controls.AddAt(1, uclMyControl) <BR><BR>This does not show my control... <BR><BR>I have tried this method: <BR><BR>Dim uclCreateTextBox As Control = LoadControl("blah/CreateTextBox.ascx") <BR>uclCreateTextBox.Visible = True <BR>Controls.AddAt(1, uclCreateTextBox) <BR><BR>While this shows the control it does not expose the control&#039;s properties, thus the control does not exactly work properly... <BR><BR><BR>The ultimate goal is to have interface code that is highly reusable and have an application interface that is very dynamic in nature. <BR><BR><BR>Perhaps I am overlooking a less complicated method of achieving this goal. <BR><BR><BR>Any input is appreciated.

  2. #2
    Join Date
    Dec 1969

    Default RE: Seting Properties of Dynamic Controls

    I don&#039;t normally use .ascx files to create controls, I create server controls instead, but I have gotten them to work. I used a placeholder to determine where on the page my control would be. What you need to do is on your aspx container page, reference your control:<BR><BR>&#060;%@ Reference Control="CreateTextBox.ascx" %&#062;<BR><BR>Also put a placeholder on the page. In the code behind for that page, you need to create a variable for the control (I do this at the page level so it can be referenced from any of the container page methods). Also dim the placeholder.<BR><BR>Public uclCreateTextBox As MyProject.MyControlClass<BR>Pulic phUserControl as Placeholder<BR><BR>Then you also need to load the control somewhere (I do it in the page_load method).<BR><BR>uclCreateTextBox = CTYPE(LoadControl("CreateTextBox.ascx", MyProject.MyControlClass)<BR>phUserControl.Control s.Add(uclCreateTextBox)<BR><BR>I hope that all makes sense to you. If not, I&#039;ll try again.<BR><BR>Sara<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts