Accessing UserControl properties - NullRef Exception

Discussion in 'ASP .Net Web Controls' started by jat, Jun 12, 2004.

  1. jat

    jat Guest

    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
     
    jat, Jun 12, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    2
    Views:
    575
  2. Phl
    Replies:
    2
    Views:
    548
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
  3. Replies:
    2
    Views:
    625
  4. protic
    Replies:
    0
    Views:
    371
    protic
    Oct 15, 2008
  5. jat

    Accessing UserControl properties - NullRef Exception

    jat, Jun 12, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    187
Loading...

Share This Page