Home All Groups Group Topic Archive Search About

override default values in a constructor

Author
11 Jun 2005 7:10 PM
TJS
How can I override the  default values, of a class constructor , from an
ASP.net page ?

    Public Sub New(  )
        HeaderStyle.BackColor = ColorTranslator.FromHtml("#5C85AD")
        HeaderStyle.ForeColor = Color.White
        HeaderStyle.Font.Bold = True
    End Sub

Author
12 Jun 2005 10:26 AM
Teemu Keiski
If you can derive your own class from it then that way, so that create a new
default constructor (in the derived class) where base class constructor is
called, and set the new default values after that call.

Otherwise you are "at mercy" of the class's API (methods and properties) so
that can you access those properties via class's public interface and just
set them.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Are all your drivers up to date? click for free checkup

Author
12 Jun 2005 5:13 PM
TJS
It is my own class, but I don't know what is meant by "create a new default
constructor where base class constructor is
  called", I thought there was only one?


Show quoteHide quote
"Teemu Keiski" <jot***@aspalliance.com> wrote in message
news:eN%23kBlzbFHA.2756@tk2msftngp13.phx.gbl...
> If you can derive your own class from it then that way, so that create a
> new default constructor (in the derived class) where base class
> constructor is called, and set the new default values after that call.
>
> Otherwise you are "at mercy" of the class's API (methods and properties)
> so that can you access those properties via class's public interface and
> just set them.
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
Author
12 Jun 2005 6:34 PM
Craig Deelsnyder
On Sun, 12 Jun 2005 12:13:10 -0500, TJS <nospam@here.com> wrote:

Show quoteHide quote
> It is my own class, but I don't know what is meant by "create a new 
> default
> constructor where base class constructor is
>   called", I thought there was only one?
>
>
> "Teemu Keiski" <jot***@aspalliance.com> wrote in message
> news:eN%23kBlzbFHA.2756@tk2msftngp13.phx.gbl...
>> If you can derive your own class from it then that way, so that create a
>> new default constructor (in the derived class) where base class
>> constructor is called, and set the new default values after that call.
>>
>> Otherwise you are "at mercy" of the class's API (methods and properties)
>> so that can you access those properties via class's public interface and
>> just set them.
>>
>> --
>> Teemu Keiski
>> ASP.NET MVP, AspInsider
>> Finland, EU
>> http://blogs.aspadvice.com/joteke
>>
>
>

Constructors are not inherited (and then not overridden) by derived 
classes; all classes get an empty default constructor (New()) that does 
nothing.  If you wish to 'override' a constructor, you have to redefine it 
in the derived class, and if you wish to still run the constructor logic 
that was defined in the superclass, you must call it in the first line of 
code of the constructor.  I believe VB.NET uses MyBase:

http://www.vbip.com/books/1861004915/chapter_4915_07.asp

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Author
12 Jun 2005 7:24 PM
TJS
thanks for the link, it confirms that constructors can be overriden and that
I have to explicitly add "MyBase.new" to the constructor, but it never tells
me how to overrride the values in the constructor, or how to call the
constructor with the override values from an ASPX file.








Show quoteHide quote
"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op.sr9skcb675dg5d@cowboy.hsd1.mn.comcast.net...
> On Sun, 12 Jun 2005 12:13:10 -0500, TJS <nospam@here.com> wrote:
>
>> It is my own class, but I don't know what is meant by "create a new
>> default
>> constructor where base class constructor is
>>   called", I thought there was only one?
>>
>>
>> "Teemu Keiski" <jot***@aspalliance.com> wrote in message
>> news:eN%23kBlzbFHA.2756@tk2msftngp13.phx.gbl...
>>> If you can derive your own class from it then that way, so that create a
>>> new default constructor (in the derived class) where base class
>>> constructor is called, and set the new default values after that call.
>>>
>>> Otherwise you are "at mercy" of the class's API (methods and properties)
>>> so that can you access those properties via class's public interface and
>>> just set them.
>>>
>>> --
>>> Teemu Keiski
>>> ASP.NET MVP, AspInsider
>>> Finland, EU
>>> http://blogs.aspadvice.com/joteke
>>>
>>
>>
>
> Constructors are not inherited (and then not overridden) by derived
> classes; all classes get an empty default constructor (New()) that does
> nothing.  If you wish to 'override' a constructor, you have to redefine it
> in the derived class, and if you wish to still run the constructor logic
> that was defined in the superclass, you must call it in the first line of
> code of the constructor.  I believe VB.NET uses MyBase:
>
> http://www.vbip.com/books/1861004915/chapter_4915_07.asp
>
> --
> Craig Deelsnyder
> Microsoft MVP - ASP/ASP.NET

Bookmark and Share