Inheriting from Custom Control

Discussion in 'ASP .Net' started by luminousc@yahoo.com, Aug 17, 2005.

  1. Guest

    Hi guys,

    I'm still a relative newbie at oop, as my background has been in old
    fashioned vanilla ASP, so please try to make your responses as simple
    as possible.

    I'm having issues with inheritence in my c#.net app. I've built a basic
    web control with some members and properties. I'm now trying to create
    a more specific class that uses all the base properties and then adds
    some more for a specific purpose. I can't seem to find the right syntax
    to get this to work.

    simplified Example:

    public System.Web.UI.WebControls.Table wizardBaseTable;
    public class BaseWizard : System.Web.UI.UserControl
    {
    public Hashtable WizardEventLog = new Hashtable();
    }

    and:

    public class wizard_Request : DTS_UI.Components.Wizards.BaseWizard
    {
    WizardEventLog.Add(DateTime.Now.ToLongTimeString() + " Wizard
    Initialised","<status at init here>");
    string aString = wizardBaseTable.ID.ToString();
    }

    Basically, the WizardEventLog.Add() line executes fine and I can see
    the entry added successfully, but when it get's to referencing the
    wizardBaseTable, the app crashes with a null reference error even
    though the Table is initialised ok in the markup file of the base
    control version.

    I'm guessing that maybe I have to use something like the LoadControl()
    method when defining the inheritence but I can't find anything that I
    understand on Google / GoogleGroups

    Thanks

    C Poole
    , Aug 17, 2005
    #1
    1. Advertising

  2. Save yourself a lot of headaches, and don't try to use inheritance with
    UserControls (at least right away). Create a Custom Control that inherits
    System.Web.UI.Control, and go from there. Here is a link to the online .Net
    SDK section on creating custom Controls for ASP.Net:

    http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopingwebformscontrols.asp?frame=true

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Paranoia is just a state of mind.

    <> wrote in message
    news:...
    > Hi guys,
    >
    > I'm still a relative newbie at oop, as my background has been in old
    > fashioned vanilla ASP, so please try to make your responses as simple
    > as possible.
    >
    > I'm having issues with inheritence in my c#.net app. I've built a basic
    > web control with some members and properties. I'm now trying to create
    > a more specific class that uses all the base properties and then adds
    > some more for a specific purpose. I can't seem to find the right syntax
    > to get this to work.
    >
    > simplified Example:
    >
    > public System.Web.UI.WebControls.Table wizardBaseTable;
    > public class BaseWizard : System.Web.UI.UserControl
    > {
    > public Hashtable WizardEventLog = new Hashtable();
    > }
    >
    > and:
    >
    > public class wizard_Request : DTS_UI.Components.Wizards.BaseWizard
    > {
    > WizardEventLog.Add(DateTime.Now.ToLongTimeString() + " Wizard
    > Initialised","<status at init here>");
    > string aString = wizardBaseTable.ID.ToString();
    > }
    >
    > Basically, the WizardEventLog.Add() line executes fine and I can see
    > the entry added successfully, but when it get's to referencing the
    > wizardBaseTable, the app crashes with a null reference error even
    > though the Table is initialised ok in the markup file of the base
    > control version.
    >
    > I'm guessing that maybe I have to use something like the LoadControl()
    > method when defining the inheritence but I can't find anything that I
    > understand on Google / GoogleGroups
    >
    > Thanks
    >
    > C Poole
    >
    Kevin Spencer, Aug 17, 2005
    #2
    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. Jonah Olsson
    Replies:
    1
    Views:
    562
    Scott Allen
    Apr 5, 2005
  2. =?Utf-8?B?V2ViTWF0cml4?=

    Creating custom gridview (inheriting from gridview class)

    =?Utf-8?B?V2ViTWF0cml4?=, Oct 21, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    544
    =?Utf-8?B?RGFsZQ==?=
    Oct 22, 2006
  3. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  4. Ole
    Replies:
    0
    Views:
    141
  5. Damien

    Inheriting Custom Control

    Damien, Jul 14, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    122
    Chris Kennedy
    Jul 15, 2005
Loading...

Share This Page