Facade for 3rd party controls, CompositeControl

Discussion in 'ASP .Net' started by Mark, Aug 1, 2008.

  1. Mark

    Mark Guest

    Hi...

    Tried posting this on Build Controls but then saw that's a pretty slow
    group...

    Kind of a typical request from product management - they want to be able to
    swap in different 3rd party controls depending on their whim and the day. In
    this case, they want to support FreeTextBox and Cute Editor interchangably.

    I've been trying to put together a container control derived from
    CompositeControl to put a facade around the interaction. Depending on the
    configuration, I want to put a FreeTextBox2 or a cute editor control into the
    ControlCollection.

    I overrode CreateChildControls() to set things up. That seems to get the
    controls created and initialized, but not rendered.

    I overrode my CompositeControl.Render() method to render the child, but
    FreeTextBox2 (my first test case) has some member variables that are only
    initialized in FreeTextBox2.OnPreRender(), which apparently hasn't been
    called.

    I tried to override my CompositeControl.OnPreRender() but since
    OnPreRender() is protected, I can't call my child FreeTextBox2.OnPreRender().

    Am I just barking up the wrong tree here? What is the best way to make a
    shell container just to hold another container of choice? How do you get the
    controls in the collection hooked up to get all of the various calls in the
    stages of execution?

    Thanks
    Mark
     
    Mark, Aug 1, 2008
    #1
    1. Advertising

  2. It's an odd request, usually you can do this sort of thing quite easily with
    a component that doesn't have a user control for instance, a db provider.
    With a user interface, things get odd because you have to be concerned with
    two paths: backend and front-end.

    --

    Regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    Download OWC Black Book, 2nd Edition
    Exclusively on www.lulu.com/owc $15.00
    Need a free copy of VSTS 2008 w/ MSDN Premium?
    http://msmvps.com/blogs/alvin/Default.aspx
    -------------------------------------------------------


    "Mark" <> wrote in message
    news:...
    > Hi...
    >
    > Tried posting this on Build Controls but then saw that's a pretty slow
    > group...
    >
    > Kind of a typical request from product management - they want to be able
    > to
    > swap in different 3rd party controls depending on their whim and the day.
    > In
    > this case, they want to support FreeTextBox and Cute Editor
    > interchangably.
    >
    > I've been trying to put together a container control derived from
    > CompositeControl to put a facade around the interaction. Depending on the
    > configuration, I want to put a FreeTextBox2 or a cute editor control into
    > the
    > ControlCollection.
    >
    > I overrode CreateChildControls() to set things up. That seems to get the
    > controls created and initialized, but not rendered.
    >
    > I overrode my CompositeControl.Render() method to render the child, but
    > FreeTextBox2 (my first test case) has some member variables that are only
    > initialized in FreeTextBox2.OnPreRender(), which apparently hasn't been
    > called.
    >
    > I tried to override my CompositeControl.OnPreRender() but since
    > OnPreRender() is protected, I can't call my child
    > FreeTextBox2.OnPreRender().
    >
    > Am I just barking up the wrong tree here? What is the best way to make a
    > shell container just to hold another container of choice? How do you get
    > the
    > controls in the collection hooked up to get all of the various calls in
    > the
    > stages of execution?
    >
    > Thanks
    > Mark
    >
    >
     
    Alvin Bruney [ASP.NET MVP], Aug 3, 2008
    #2
    1. Advertising

  3. Mark

    Mark Guest

    Hi Alvin...

    Thanks for responding.

    I bow to your expertise, but if I must press ahead on this route, which do
    you think would be the best approach:

    1) wrapper the 3rd party components so that they expose a method I *can*
    call at most phases (like OnPreRender())

    2) Not add my CompositeControl to the page writer.AddControl(), but add the
    child component instead

    3) Add my CompositeControl and the child control to the page writer but
    override my container Render method to do nothing

    My container really doesn't want to do anything other than make sure the
    3rdparty component of choice gets on the page - don't want any rendering, all
    actions would just be a pass-through.

    Which of the above would be the best approach, or is there another I've just
    missed?
    Thanks
    Mark


    "Alvin Bruney [ASP.NET MVP]" wrote:

    > It's an odd request, usually you can do this sort of thing quite easily with
    > a component that doesn't have a user control for instance, a db provider.
    > With a user interface, things get odd because you have to be concerned with
    > two paths: backend and front-end.
    >
    > --
    >
    > Regards,
    > Alvin Bruney [MVP ASP.NET]
    >
    > [Shameless Author plug]
    > Download OWC Black Book, 2nd Edition
    > Exclusively on www.lulu.com/owc $15.00
    > Need a free copy of VSTS 2008 w/ MSDN Premium?
    > http://msmvps.com/blogs/alvin/Default.aspx
    > -------------------------------------------------------
    >
    >
    > "Mark" <> wrote in message
    > news:...
    > > Hi...
    > >
    > > Tried posting this on Build Controls but then saw that's a pretty slow
    > > group...
    > >
    > > Kind of a typical request from product management - they want to be able
    > > to
    > > swap in different 3rd party controls depending on their whim and the day.
    > > In
    > > this case, they want to support FreeTextBox and Cute Editor
    > > interchangably.
    > >
    > > I've been trying to put together a container control derived from
    > > CompositeControl to put a facade around the interaction. Depending on the
    > > configuration, I want to put a FreeTextBox2 or a cute editor control into
    > > the
    > > ControlCollection.
    > >
    > > I overrode CreateChildControls() to set things up. That seems to get the
    > > controls created and initialized, but not rendered.
    > >
    > > I overrode my CompositeControl.Render() method to render the child, but
    > > FreeTextBox2 (my first test case) has some member variables that are only
    > > initialized in FreeTextBox2.OnPreRender(), which apparently hasn't been
    > > called.
    > >
    > > I tried to override my CompositeControl.OnPreRender() but since
    > > OnPreRender() is protected, I can't call my child
    > > FreeTextBox2.OnPreRender().
    > >
    > > Am I just barking up the wrong tree here? What is the best way to make a
    > > shell container just to hold another container of choice? How do you get
    > > the
    > > controls in the collection hooked up to get all of the various calls in
    > > the
    > > stages of execution?
    > >
    > > Thanks
    > > Mark
    > >
    > >
     
    Mark, Aug 3, 2008
    #3
  4. Hi Mark,

    As for composite control, I think using "CreateChildControls" method is the
    reasonable approach. For your scenario, if you want to wrapper some other
    existing 3rd party control in your composite control. You can simply
    override the composite control and add the 3rd party control instance into
    its "Controls" colleciton, and the runtime will automatically render the
    nested controls. For example:

    =============================
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
    public class ServerControl1 : CompositeControl
    {
    .......................

    protected override void CreateChildControls()
    {
    Controls.Clear();

    Button btn = new Button();
    btn.ID = "btnOne";
    btn.Text = "Button One";
    btn.Click += delegate { Page.Response.Write("<br/>button one is
    clicked!"); };

    Controls.Add(btn);

    Controls.Add(new LiteralControl("<br/><br/>"));

    //add FreeTextBox

    FreeTextBox ftb = new FreeTextBox();
    ftb.ID = "ftb1";

    Controls.Add(ftb);
    }

    }
    =========================================

    the above composite control will output a Button and a FreeTextBox control
    as child control on page.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: =?Utf-8?B?TWFyaw==?= <>
    >Subject: Facade for 3rd party controls, CompositeControl
    >Date: Fri, 1 Aug 2008 15:03:09 -0700


    >
    >Hi...
    >
    >Tried posting this on Build Controls but then saw that's a pretty slow
    >group...
    >
    >Kind of a typical request from product management - they want to be able

    to
    >swap in different 3rd party controls depending on their whim and the day.

    In
    >this case, they want to support FreeTextBox and Cute Editor interchangably.
    >
    >I've been trying to put together a container control derived from
    >CompositeControl to put a facade around the interaction. Depending on the
    >configuration, I want to put a FreeTextBox2 or a cute editor control into

    the
    >ControlCollection.
    >
    >I overrode CreateChildControls() to set things up. That seems to get the
    >controls created and initialized, but not rendered.
    >
    >I overrode my CompositeControl.Render() method to render the child, but
    >FreeTextBox2 (my first test case) has some member variables that are only
    >initialized in FreeTextBox2.OnPreRender(), which apparently hasn't been
    >called.
    >
    >I tried to override my CompositeControl.OnPreRender() but since
    >OnPreRender() is protected, I can't call my child

    FreeTextBox2.OnPreRender().
    >
    >Am I just barking up the wrong tree here? What is the best way to make a
    >shell container just to hold another container of choice? How do you get

    the
    >controls in the collection hooked up to get all of the various calls in

    the
    >stages of execution?
    >
    >Thanks
    >Mark
    >
    >
    >
     
    Steven Cheng [MSFT], Aug 4, 2008
    #4
  5. Mark

    Mark Guest

    Hi Steven...

    All my attempts have been basically the code you have below. The only
    problem is that it doesn't work, which is why I posted here.

    Overriding CreateChildControls() gets the ControlCollection populated, but
    apparently not rendered.

    When I override my CompositeControl.Render or RenderControl methods and
    explicitly call Render on the children, I run into the next error -
    FreeTextBox2 seems to only initialize certain members during the
    OnPreRender() phase, which again doesn't seem to be called when a control is
    in a CompositeControl.

    So the *next* problem, which cause me to post, is that OnPreRender() is
    protected, so I can't override my CompositeControl.OnPreRender() and make it
    invoke the OnPreRender() on the children; I can't get to it.

    So while it sounds like a nice idea to throw a CompositeControl around it,
    it doesn't look like the CompositeControl has the wiring to support passing
    through all the actions to the children in the ControlCollection.

    That's the nub of my problem.

    Thanks
    Mark


    "Steven Cheng [MSFT]" wrote:

    > Hi Mark,
    >
    > As for composite control, I think using "CreateChildControls" method is the
    > reasonable approach. For your scenario, if you want to wrapper some other
    > existing 3rd party control in your composite control. You can simply
    > override the composite control and add the 3rd party control instance into
    > its "Controls" colleciton, and the runtime will automatically render the
    > nested controls. For example:
    >
    > =============================
    > [DefaultProperty("Text")]
    > [ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
    > public class ServerControl1 : CompositeControl
    > {
    > .......................
    >
    > protected override void CreateChildControls()
    > {
    > Controls.Clear();
    >
    > Button btn = new Button();
    > btn.ID = "btnOne";
    > btn.Text = "Button One";
    > btn.Click += delegate { Page.Response.Write("<br/>button one is
    > clicked!"); };
    >
    > Controls.Add(btn);
    >
    > Controls.Add(new LiteralControl("<br/><br/>"));
    >
    > //add FreeTextBox
    >
    > FreeTextBox ftb = new FreeTextBox();
    > ftb.ID = "ftb1";
    >
    > Controls.Add(ftb);
    > }
    >
    > }
    > =========================================
    >
    > the above composite control will output a Button and a FreeTextBox control
    > as child control on page.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    > --------------------
    > >From: =?Utf-8?B?TWFyaw==?= <>
    > >Subject: Facade for 3rd party controls, CompositeControl
    > >Date: Fri, 1 Aug 2008 15:03:09 -0700

    >
    > >
    > >Hi...
    > >
    > >Tried posting this on Build Controls but then saw that's a pretty slow
    > >group...
    > >
    > >Kind of a typical request from product management - they want to be able

    > to
    > >swap in different 3rd party controls depending on their whim and the day.

    > In
    > >this case, they want to support FreeTextBox and Cute Editor interchangably.
    > >
    > >I've been trying to put together a container control derived from
    > >CompositeControl to put a facade around the interaction. Depending on the
    > >configuration, I want to put a FreeTextBox2 or a cute editor control into

    > the
    > >ControlCollection.
    > >
    > >I overrode CreateChildControls() to set things up. That seems to get the
    > >controls created and initialized, but not rendered.
    > >
    > >I overrode my CompositeControl.Render() method to render the child, but
    > >FreeTextBox2 (my first test case) has some member variables that are only
    > >initialized in FreeTextBox2.OnPreRender(), which apparently hasn't been
    > >called.
    > >
    > >I tried to override my CompositeControl.OnPreRender() but since
    > >OnPreRender() is protected, I can't call my child

    > FreeTextBox2.OnPreRender().
    > >
    > >Am I just barking up the wrong tree here? What is the best way to make a
    > >shell container just to hold another container of choice? How do you get

    > the
    > >controls in the collection hooked up to get all of the various calls in

    > the
    > >stages of execution?
    > >
    > >Thanks
    > >Mark
    > >
    > >
    > >

    >
    >
     
    Mark, Aug 4, 2008
    #5
  6. Thanks for your reply Mark,

    So you used the similar code(for the composite control) but cannot get the
    Freetextbox sub control displayed? Regardless of the code and page
    template, what I can think about is the control version, what version of
    the FreeTextBox control are you using? I'm using the one for .net framework
    2.0

    http://freetextbox.com/download/default.aspx

    And I direclty modify the sample application to use a custom composite
    control I used for testing. If you need, I can send you my test page and
    control code. You can ping me at the following address:

    "stcheng" + @ + "microsoft.com"

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: =?Utf-8?B?TWFyaw==?= <>
    >References: <>

    <U$>
    >Subject: RE: Facade for 3rd party controls, CompositeControl
    >Date: Mon, 4 Aug 2008 08:59:00 -0700


    >
    >Hi Steven...
    >
    >All my attempts have been basically the code you have below. The only
    >problem is that it doesn't work, which is why I posted here.
    >
    >Overriding CreateChildControls() gets the ControlCollection populated, but
    >apparently not rendered.
    >
    >When I override my CompositeControl.Render or RenderControl methods and
    >explicitly call Render on the children, I run into the next error -
    >FreeTextBox2 seems to only initialize certain members during the
    >OnPreRender() phase, which again doesn't seem to be called when a control

    is
    >in a CompositeControl.
    >
    >So the *next* problem, which cause me to post, is that OnPreRender() is
    >protected, so I can't override my CompositeControl.OnPreRender() and make

    it
    >invoke the OnPreRender() on the children; I can't get to it.
    >
    >So while it sounds like a nice idea to throw a CompositeControl around it,
    >it doesn't look like the CompositeControl has the wiring to support

    passing
    >through all the actions to the children in the ControlCollection.
    >
    >That's the nub of my problem.
    >
    >Thanks
    >Mark
    >
    >
     
    Steven Cheng [MSFT], Aug 5, 2008
    #6
  7. Hi Mark,

    I've just replied your email with a test project(with a custom control
    which wrapper FreeTextBox control). Also, i've added some suggestion about
    the nested control's auto-generated ID.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------

    >Content-Transfer-Encoding: 7bit
    >From: (Steven Cheng [MSFT])
    >Organization: Microsoft
    >Date: Tue, 05 Aug 2008 06:17:08 GMT
    >Subject: RE: Facade for 3rd party controls, CompositeControl


    >Thanks for your reply Mark,
    >
    >So you used the similar code(for the composite control) but cannot get the
    >Freetextbox sub control displayed? Regardless of the code and page
    >template, what I can think about is the control version, what version of
    >the FreeTextBox control are you using? I'm using the one for .net

    framework
    >2.0
    >
    >http://freetextbox.com/download/default.aspx
    >
    >And I direclty modify the sample application to use a custom composite
    >control I used for testing. If you need, I can send you my test page and
    >control code. You can ping me at the following address:
    >
    >"stcheng" + @ + "microsoft.com"
    >
    >Sincerely,
    >
    >Steven Cheng
    >
    >Microsoft MSDN Online Support Lead
    >
    >
    >Delighting our customers is our #1 priority. We welcome your comments and
    >suggestions about how we can improve the support we provide to you. Please
    >feel free to let my manager know what you think of the level of service
    >provided. You can send feedback directly to my manager at:
    >.
    >
    >==================================================
    >Get notification to my posts through email? Please refer to
    >http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#noti

    f
    >ications.
    >
    >==================================================
    >This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >--------------------
    >>From: =?Utf-8?B?TWFyaw==?= <>
    >>References: <>

    ><U$>
    >>Subject: RE: Facade for 3rd party controls, CompositeControl
    >>Date: Mon, 4 Aug 2008 08:59:00 -0700

    >
    >>
     
    Steven Cheng [MSFT], Aug 7, 2008
    #7
    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. Tian Min Huang
    Replies:
    0
    Views:
    491
    Tian Min Huang
    Jul 28, 2003
  2. Aaron
    Replies:
    2
    Views:
    314
    Natty Gur
    Aug 14, 2003
  3. Darren Clark
    Replies:
    2
    Views:
    336
    David Krussow
    Apr 10, 2004
  4. Max
    Replies:
    1
    Views:
    327
  5. Mark

    Facade for 3rd party controls, CompositeControl?

    Mark, Aug 1, 2008, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    1,410
    Steven Cheng [MSFT]
    Aug 4, 2008
Loading...

Share This Page