user controls design question

Discussion in 'ASP .Net' started by sonic, Jul 11, 2006.

  1. sonic

    sonic Guest

    Hello,
    I am trying to create a custom control hierarchy that encapsulates web
    controls in my framework and run into a interesting problem.

    my framework will automatically save all user control
    values/preferences and initiate them from query string. My framework
    will provide all necessary work and all the developers will have to do
    is:
    <myCo:CustomTextbox id="myText" runat="server" />
    or
    <myCo:CustomDropDown id="myDropDown" runat="server" />
    and everything will be handled.

    to achieve this, all of my controls would inherit from
    CustomBaseControl which inherits WebControl, and adds additional
    methods/events for improved personalization etc..

    it works great, accept the web control strong typing is lost during the
    declaration of the custom controls since they all inherit webcontrol.

    so i cannot do
    <myCo:CustomTextBox id="myText" runat="server" Text="this will berak"
    />

    since c# does not support multiple inheritance, i have a choice of
    inheriting from TextBox, and my own interface which would ensure that
    all custom controls would implement necessary methods/event, or
    inheriting from baseclass which will provide all of my controls with
    common functionality, and running into the problem above.

    any thoughts ?
     
    sonic, Jul 11, 2006
    #1
    1. Advertising

  2. sonic

    Axel Dahmen Guest

    AFAIK you're lost on this. I also strongly suggest .NET to support multiple
    inheritance.

    Currently all you can do is to not derive from your base class but instead
    derive e.g. from asp:TextBox and to add a single custom interface to your
    class library plus a base class implementing your features and then
    implement the interface using stub functions in your derived class
    (=aggregation) to call the base class's function... *yuk*

    HTH,
    Axel Dahmen


    --------------------
    "sonic" <> wrote in message
    news:...
    > Hello,
    > I am trying to create a custom control hierarchy that encapsulates web
    > controls in my framework and run into a interesting problem.
    >
    > my framework will automatically save all user control
    > values/preferences and initiate them from query string. My framework
    > will provide all necessary work and all the developers will have to do
    > is:
    > <myCo:CustomTextbox id="myText" runat="server" />
    > or
    > <myCo:CustomDropDown id="myDropDown" runat="server" />
    > and everything will be handled.
    >
    > to achieve this, all of my controls would inherit from
    > CustomBaseControl which inherits WebControl, and adds additional
    > methods/events for improved personalization etc..
    >
    > it works great, accept the web control strong typing is lost during the
    > declaration of the custom controls since they all inherit webcontrol.
    >
    > so i cannot do
    > <myCo:CustomTextBox id="myText" runat="server" Text="this will berak"
    > />
    >
    > since c# does not support multiple inheritance, i have a choice of
    > inheriting from TextBox, and my own interface which would ensure that
    > all custom controls would implement necessary methods/event, or
    > inheriting from baseclass which will provide all of my controls with
    > common functionality, and running into the problem above.
    >
    > any thoughts ?
    >
     
    Axel Dahmen, Jul 11, 2006
    #2
    1. Advertising

  3. sonic

    sonic Guest

    yeah..
    so what about exposing the underlying type.
    if i inherit from MyCustomControl and that control handles all common
    functionality, than inside of there, is generate the actual TextBox
    control and render it manually.
    If i expose that control developers could still access it on codebehind
    files by:
    ((TextBox)myText.RenderedControl).Size = 20;
    is it possible to do this in aspx page ?
    something like:
    <myCo:MyTextBox id="..." id="myText" RenderedControl-Size="30" />
    etc..
    would i have to do anything special to achieve this?


    Axel Dahmen wrote:
    > AFAIK you're lost on this. I also strongly suggest .NET to support multiple
    > inheritance.
    >
    > Currently all you can do is to not derive from your base class but instead
    > derive e.g. from asp:TextBox and to add a single custom interface to your
    > class library plus a base class implementing your features and then
    > implement the interface using stub functions in your derived class
    > (=aggregation) to call the base class's function... *yuk*
    >
    > HTH,
    > Axel Dahmen
    >
    >
    > --------------------
    > "sonic" <> wrote in message
    > news:...
    > > Hello,
    > > I am trying to create a custom control hierarchy that encapsulates web
    > > controls in my framework and run into a interesting problem.
    > >
    > > my framework will automatically save all user control
    > > values/preferences and initiate them from query string. My framework
    > > will provide all necessary work and all the developers will have to do
    > > is:
    > > <myCo:CustomTextbox id="myText" runat="server" />
    > > or
    > > <myCo:CustomDropDown id="myDropDown" runat="server" />
    > > and everything will be handled.
    > >
    > > to achieve this, all of my controls would inherit from
    > > CustomBaseControl which inherits WebControl, and adds additional
    > > methods/events for improved personalization etc..
    > >
    > > it works great, accept the web control strong typing is lost during the
    > > declaration of the custom controls since they all inherit webcontrol.
    > >
    > > so i cannot do
    > > <myCo:CustomTextBox id="myText" runat="server" Text="this will berak"
    > > />
    > >
    > > since c# does not support multiple inheritance, i have a choice of
    > > inheriting from TextBox, and my own interface which would ensure that
    > > all custom controls would implement necessary methods/event, or
    > > inheriting from baseclass which will provide all of my controls with
    > > common functionality, and running into the problem above.
    > >
    > > any thoughts ?
    > >
     
    sonic, Jul 11, 2006
    #3
  4. sonic

    sonic Guest

    this no multiple inheritance is a real kick in the nuts.
     
    sonic, Jul 11, 2006
    #4
  5. sonic

    Axel Dahmen Guest

    how would you want to do the casting if you can't derive from it? If you're
    deriving from Control you can't assign some constructor argument (or
    whatever) to yourself...

    nono... unfortunately this doesn't work... *sigh*


    ------------
    "sonic" <> wrote in message
    news:...
    > yeah..
    > so what about exposing the underlying type.
    > if i inherit from MyCustomControl and that control handles all common
    > functionality, than inside of there, is generate the actual TextBox
    > control and render it manually.
    > If i expose that control developers could still access it on codebehind
    > files by:
    > ((TextBox)myText.RenderedControl).Size = 20;
    > is it possible to do this in aspx page ?
    > something like:
    > <myCo:MyTextBox id="..." id="myText" RenderedControl-Size="30" />
    > etc..
    > would i have to do anything special to achieve this?
    >
    >
    > Axel Dahmen wrote:
    > > AFAIK you're lost on this. I also strongly suggest .NET to support

    multiple
    > > inheritance.
    > >
    > > Currently all you can do is to not derive from your base class but

    instead
    > > derive e.g. from asp:TextBox and to add a single custom interface to

    your
    > > class library plus a base class implementing your features and then
    > > implement the interface using stub functions in your derived class
    > > (=aggregation) to call the base class's function... *yuk*
    > >
    > > HTH,
    > > Axel Dahmen
    > >
    > >
    > > --------------------
    > > "sonic" <> wrote in message
    > > news:...
    > > > Hello,
    > > > I am trying to create a custom control hierarchy that encapsulates web
    > > > controls in my framework and run into a interesting problem.
    > > >
    > > > my framework will automatically save all user control
    > > > values/preferences and initiate them from query string. My framework
    > > > will provide all necessary work and all the developers will have to do
    > > > is:
    > > > <myCo:CustomTextbox id="myText" runat="server" />
    > > > or
    > > > <myCo:CustomDropDown id="myDropDown" runat="server" />
    > > > and everything will be handled.
    > > >
    > > > to achieve this, all of my controls would inherit from
    > > > CustomBaseControl which inherits WebControl, and adds additional
    > > > methods/events for improved personalization etc..
    > > >
    > > > it works great, accept the web control strong typing is lost during

    the
    > > > declaration of the custom controls since they all inherit webcontrol.
    > > >
    > > > so i cannot do
    > > > <myCo:CustomTextBox id="myText" runat="server" Text="this will berak"
    > > > />
    > > >
    > > > since c# does not support multiple inheritance, i have a choice of
    > > > inheriting from TextBox, and my own interface which would ensure that
    > > > all custom controls would implement necessary methods/event, or
    > > > inheriting from baseclass which will provide all of my controls with
    > > > common functionality, and running into the problem above.
    > > >
    > > > any thoughts ?
    > > >

    >
     
    Axel Dahmen, Jul 17, 2006
    #5
    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. Kevin Spencer

    Loading a user controls in Design View

    Kevin Spencer, Jul 24, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    415
    oneeye
    Jul 29, 2003
  2. Earl Teigrob
    Replies:
    3
    Views:
    602
    John Saunders
    Jun 10, 2004
  3. =?Utf-8?B?TmF0aGFuVg==?=

    User Controls/Design Best Practices

    =?Utf-8?B?TmF0aGFuVg==?=, Oct 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    435
    DWinter
    Oct 2, 2004
  4. Faizan Ahmed
    Replies:
    1
    Views:
    305
    John Saunders
    Jan 4, 2005
  5. Faizan Ahmed
    Replies:
    1
    Views:
    383
    John Saunders
    Jan 4, 2005
Loading...

Share This Page