jeudi 2 juillet 2015

Call to a WebUserControl method by reflection initializating controls inside (vb.net or c#)

I´m trying to call a method by reflection that is on a webUserControl. The method fails because it uses the property of a children (TextBox):

Dim user As String = Me.txtUser.Text.Trim.ToLower

In fact txtUser is nothing so it seems that designer is not initializated.

I use an activator for the target as:

-->

target = Activator.CreateInstance(tipo, listInitials.ToArray)

Dim webpage As System.Web.UI.Page
Dim ctr As UserControl
Dim sb As New StringBuilder()
Dim sw As New StringWriter(sb)
Dim htw As New HtmlTextWriter(sw)
ctr = TryCast(target, UserControl)
webpage = New FormlessPage()
ctr.RenderControl(htw)
webpage.Controls.Add(ctr) 

<-- inspecting I can see ctr.controls.count = 0 :(

¿Any idea of why it happens and how to initializate child controls?





Aucun commentaire:

Enregistrer un commentaire