adding a XML control to a web custom control

Discussion in 'ASP .Net' started by Brian Henry, Nov 14, 2004.

  1. Brian Henry

    Brian Henry Guest

    I want to create a web custom control (not a user web control) that I can
    add a XML translation control into, how would I do this? I am using the web
    custom control as a template that I can add to the page, but it depends on
    other Web Form controls inside it but I do not know how to add the other web
    form controls such as a XML web form control into this programatticly
    created control. thanks
    Brian Henry, Nov 14, 2004
    #1
    1. Advertising

  2. Brian Henry

    Derek Harmon Guest

    "Brian Henry" <> wrote in message news:...
    > I want to create a web custom control (not a user web control) that I can
    > add a XML translation control into, how would I do this?


    So you've created this WebCustomControl1 type from the default web
    custom control project, right? Now you want to add an Xml web control
    into it (or perhaps several Xml web controls into it). OK, two steps.

    In your control's OnInit override (or this can also be done externally
    from the Page_Init event handler) you need to create an instance of
    the Xml web control and add it to the child Controls collection of the
    WebCustomControl1 class.

    e.g.,

    protected override void OnInit( EventArgs e)
    {
    // Always call base class's OnInit( ) in case it does anything.
    base.OnInit( e);

    // Create an Xml control.
    System.Web.UI.WebControls.Xml xmlControl1 = new Xml( );

    // Set some properties on it; in this case my XML is really xHTML so
    // it'll show up in the browser w/o too much hassle.
    xmlControl1.ID = "XmlControl1";
    xmlControl1.DocumentContent = "<span style='color:red;'>text</span>";
    xmlControl1.TransformSource = "./IdentityTransform.xsl";

    // Add the Xml control as one of this control's children.
    this.Controls.Add( xmlControl1);
    }

    Next step is that when the ASP.NET Framework tells WebCustomControl1
    to render itself, WebCustomControl1 needs to tell any child controls that they
    should render themselves.

    protected override void Render(HtmlTextWriter output)
    {
    // This line is generated automatically by the Code Wiz.
    output.Write( Text);

    // Render all child controls to this HtmlTextWriter.
    this.RenderChildren( output);
    }

    Now you should be set to go. The technique is known as "composite controls,"
    if you have further questions about them.


    Derek Harmon
    Derek Harmon, Nov 14, 2004
    #2
    1. Advertising

  3. Brian Henry

    Brian Henry Guest

    thanks!

    "Derek Harmon" <> wrote in message
    news:...
    > "Brian Henry" <> wrote in message
    > news:...
    >> I want to create a web custom control (not a user web control) that I can
    >> add a XML translation control into, how would I do this?

    >
    > So you've created this WebCustomControl1 type from the default web
    > custom control project, right? Now you want to add an Xml web control
    > into it (or perhaps several Xml web controls into it). OK, two steps.
    >
    > In your control's OnInit override (or this can also be done externally
    > from the Page_Init event handler) you need to create an instance of
    > the Xml web control and add it to the child Controls collection of the
    > WebCustomControl1 class.
    >
    > e.g.,
    >
    > protected override void OnInit( EventArgs e)
    > {
    > // Always call base class's OnInit( ) in case it does anything.
    > base.OnInit( e);
    >
    > // Create an Xml control.
    > System.Web.UI.WebControls.Xml xmlControl1 = new Xml( );
    >
    > // Set some properties on it; in this case my XML is really xHTML
    > so
    > // it'll show up in the browser w/o too much hassle.
    > xmlControl1.ID = "XmlControl1";
    > xmlControl1.DocumentContent = "<span
    > style='color:red;'>text</span>";
    > xmlControl1.TransformSource = "./IdentityTransform.xsl";
    >
    > // Add the Xml control as one of this control's children.
    > this.Controls.Add( xmlControl1);
    > }
    >
    > Next step is that when the ASP.NET Framework tells WebCustomControl1
    > to render itself, WebCustomControl1 needs to tell any child controls that
    > they
    > should render themselves.
    >
    > protected override void Render(HtmlTextWriter output)
    > {
    > // This line is generated automatically by the Code Wiz.
    > output.Write( Text);
    >
    > // Render all child controls to this HtmlTextWriter.
    > this.RenderChildren( output);
    > }
    >
    > Now you should be set to go. The technique is known as "composite
    > controls,"
    > if you have further questions about them.
    >
    >
    > Derek Harmon
    >
    >
    Brian Henry, Nov 14, 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. Web Team @ Borough of Poole

    Adding a control to a custom web control

    Web Team @ Borough of Poole, Sep 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    311
    Web Team @ Borough of Poole
    Sep 10, 2005
  2. Web Team @ Borough of Poole

    Adding a control to a custom web control

    Web Team @ Borough of Poole, Sep 10, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    406
    aa7im
    Sep 14, 2005
  3. Gibble
    Replies:
    0
    Views:
    464
    Gibble
    May 17, 2007
  4. Gibble
    Replies:
    0
    Views:
    321
    Gibble
    May 17, 2007
  5. Matt Sokol
    Replies:
    2
    Views:
    358
    Theo Tillotson
    Aug 7, 2003
Loading...

Share This Page