Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Accessing UserControl properties - NullRef Exception

Thread Tools

Accessing UserControl properties - NullRef Exception

Posts: n/a
Hi there,

I'm currently using an XML file combined with an XSLT to generate my server
controls (similar to the method as per
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!



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
Return Me.lblQuestion.Text
End Get
Set(ByVal Value As String)
Me.lblQuestion.Text = Value
End Set
End Property

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing vb of usercontrol within usercontrol protic ASP .Net 0 10-15-2008 11:26 AM
Accessing MasterPage Properties from a usercontrol on a contentpage?? ASP .Net 2 02-26-2008 01:33 PM
accessing usercontrol from another usercontrol Phl ASP .Net 2 11-18-2004 07:33 PM
Accessing usercontrol properties from another page - SERVER-SIDE John ASP .Net 2 10-17-2004 03:50 PM
Accessing UserControl properties - NullRef Exception jat ASP .Net Building Controls 0 06-12-2004 02:09 AM