Accessing UserControl properties - NullRef Exception

J

jat

Hi there,

I'm currently using an XML file combined with an XSLT to generate my server
controls (similar to the method as per
http://www.devarticles.com/c/a/ASP.NET/Creating-Dynamic-ASP.NET-Server-Contr
ols-Using-XML/ ).

The problem is - I want to use the XSLT transform to add a UserControl
(custom made) to the webform, setting various properties on the control

However, I cannot set the custom properties on the object - as I get a null
reference exception. The null reference exception occurs on the following
line - which parses the 'result' of the XML transform (i.e. the "html/xml"
defining the page)

Dim ctrls As Control = Page.ParseControl(result)

The following passed into the Page.Parsecontrol correctly renders the
UserControl (testcontrol), correctly assigning the control the id of Q2

<uc1:testcontrol id="q2" runat="server" />

However, the following code brings up a NullRef Exception on the
ParseControl method

<uc1:testcontrol id="q2" QuestTest="blahblah" runat="server" />

If I drag and drop the testcontrol to the form and set the property as per
the second example, it works. Clearly ParseControl is not instantiating my
usercontrol before it tries to assign the property (I can tell this by it
never hitting the INIT event of the UserControl).

Is there any way to overcome this?

Thanks for your help!

Jay



Note

1: In order to add my UserControl to the page - I had to prepend a <%@
Register TagPrefix=""uc1"" (blah blah) In order for the page to identify &
render my UserControl.
2: I should have added, all QuestTest is
Public Property QuestTest() As String
Get
Return Me.lblQuestion.Text
End Get
Set(ByVal Value As String)
Me.lblQuestion.Text = Value
End Set
End Property
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top