O
Omikron
Hi,
I have a problem with loading user controls dynamically on the page. I
have two simple projects: first includes user control with one
textbox.
Public Partial Class test
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreRender
TextBox1.Text = "I am loaded now " & Now.ToString("dd MMM yyyy
hh:mm:ss")
End Sub
End Class
In the second project I am putting a reference to the first one and
want to create an instance of the user control. In the Page_Load it
looks like this:
Dim str_Assembly As String = "WebApplication1, Version=1.0.0.0,
Culture=neutral, PublicToken=null"
Dim asm_ControlAssembly As System.Reflection.Assembly =
System.Reflection.Assembly.Load(str_Assembly)
Dim obj_Control As Control = CType(asm_ControlAssembly.CreateInstance
("WebApplication1.test"), Control)
PlaceHolder1.Controls.Add(obj_Control)
.....
Everything is fine, control is created, added, except the fact that
TextBox1 from the UserControl is not initalized and so I'm getting
null reference exception when it comes to Page_Load call in
UserControl...
Thanks in advance
Bartek
I have a problem with loading user controls dynamically on the page. I
have two simple projects: first includes user control with one
textbox.
Public Partial Class test
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreRender
TextBox1.Text = "I am loaded now " & Now.ToString("dd MMM yyyy
hh:mm:ss")
End Sub
End Class
In the second project I am putting a reference to the first one and
want to create an instance of the user control. In the Page_Load it
looks like this:
Dim str_Assembly As String = "WebApplication1, Version=1.0.0.0,
Culture=neutral, PublicToken=null"
Dim asm_ControlAssembly As System.Reflection.Assembly =
System.Reflection.Assembly.Load(str_Assembly)
Dim obj_Control As Control = CType(asm_ControlAssembly.CreateInstance
("WebApplication1.test"), Control)
PlaceHolder1.Controls.Add(obj_Control)
.....
Everything is fine, control is created, added, except the fact that
TextBox1 from the UserControl is not initalized and so I'm getting
null reference exception when it comes to Page_Load call in
UserControl...
Thanks in advance
Bartek