CustomControl.Page is undefined ?!?!?!

Discussion in 'ASP .Net Web Controls' started by Robert Koritnik, May 19, 2004.

  1. I ran into a strange problem. I created my own server control that inherits
    Control and INamingContainer. I override CreateChildControls() method.

    Within this method i try to register some client script block with methods,
    that the control container (the Page) provides (RegisterClientScriptBlock
    etc.) When I try to check for slient script registration on the page i get
    the "Object reference not set to an instance of an object." runtime error.
    Debugging the code I realised that Custom control's property Page (inherited
    by Control class) is null. Anybody knows why and when does that happen?

    Robert
    Robert Koritnik, May 19, 2004
    #1
    1. Advertising

  2. Robert Koritnik

    Eidolon Guest

    I think from your post, you are inheriting from the wrong class.

    It is not Control that you want to inherit from but rather:

    System.Data.Web.UI.WebControls.WebControl

    The "Web"Control is where the Page property comes from.

    HTH.


    "Robert Koritnik" <> wrote in message
    news:%...
    > I ran into a strange problem. I created my own server control that

    inherits
    > Control and INamingContainer. I override CreateChildControls() method.
    >
    > Within this method i try to register some client script block with

    methods,
    > that the control container (the Page) provides (RegisterClientScriptBlock
    > etc.) When I try to check for slient script registration on the page i get
    > the "Object reference not set to an instance of an object." runtime error.
    > Debugging the code I realised that Custom control's property Page

    (inherited
    > by Control class) is null. Anybody knows why and when does that happen?
    >
    > Robert
    >
    >
    Eidolon, May 19, 2004
    #2
    1. Advertising

  3. What you are saying would be ridiculus because Repeater for instance
    inherits from Control... Page comes from Control and not WebControl. And I
    don't need the WebControl functionality, that's why I inherit from Control.

    Check the Page property here:
    http://msdn.microsoft.com/library/d.../html/frlrfsystemwebuicontrolmemberstopic.asp

    Anyway. I figured it out. Before OnInit the Page property is not yet set so
    if you are accessing it within any get/set property block you have to check
    for its undefined value...

    --

    RobertK
    { Clever? No just smart. }

    "Eidolon" <> wrote in message
    news:...
    > I think from your post, you are inheriting from the wrong class.
    >
    > It is not Control that you want to inherit from but rather:
    >
    > System.Data.Web.UI.WebControls.WebControl
    >
    > The "Web"Control is where the Page property comes from.
    >
    > HTH.
    >
    >
    > "Robert Koritnik" <> wrote in message
    > news:%...
    > > I ran into a strange problem. I created my own server control that

    > inherits
    > > Control and INamingContainer. I override CreateChildControls() method.
    > >
    > > Within this method i try to register some client script block with

    > methods,
    > > that the control container (the Page) provides

    (RegisterClientScriptBlock
    > > etc.) When I try to check for slient script registration on the page i

    get
    > > the "Object reference not set to an instance of an object." runtime

    error.
    > > Debugging the code I realised that Custom control's property Page

    > (inherited
    > > by Control class) is null. Anybody knows why and when does that happen?
    > >
    > > Robert
    > >
    > >

    >
    >
    Robert Koritnik, May 21, 2004
    #3
    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. Eric B
    Replies:
    1
    Views:
    1,883
    Eric B
    Sep 3, 2003
  2. KMILO
    Replies:
    0
    Views:
    373
    KMILO
    Apr 22, 2005
  3. philipp

    writing a customControl

    philipp, May 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    395
    philipp
    May 18, 2005
  4. =?Utf-8?B?U3RldmU=?=

    ImageButton Click Event in CustomControl

    =?Utf-8?B?U3RldmU=?=, Feb 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    917
    =?Utf-8?B?U3RldmU=?=
    Feb 20, 2006
  5. Ashish

    CustomControl Losing Events.

    Ashish, May 22, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    379
    Ashish
    May 22, 2006
Loading...

Share This Page