I ran into a similar problem: -
I first add the UserControl dynamically, and then try to assign values ββto the internal controls (text box inside the user control). Using any event, such as INIT or LOAD, the control gives me the exception of the link , because, as you can see from the step-by-step code, the controls have not yet been created.
Later, I discovered that this problem only occurs if I declare the control through the dim statement:
Dim MyControl as new MyUserControl Me.Panel1.Controls.add(MyControl) MyControl.SetLabelText("My Name") 'Uses a method to set the label text on load.
On the other hand, if I use the control as follows, it works fine:
Dim MyControl as MyUserControl = LoadControl("MyUserControl.ascx") Me.Panel1.Controls.add(MyControl) MyControl.SetLabelText("My Label Text")
source share