![]() |
Accessing UserControl properties - NullRef Exception
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.N...T-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 |
| All times are GMT. The time now is 03:20 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.