Custom Control with content RRS feed

  • Question

  • User-1103495211 posted

    I like to build a constom control, something like a custom Panel.
    But i  don't know how i can make it like that, in this case the label

    The first step is placing:

    <div><div><div><div> above the content, and placing </div></div></div></div> after it.
    Of course lateron more, but this is something to start with.

    I made:

    <rd:rdiv Text="Hoi:" runat="server"> <asp:Label id="lblTest" runat="server" Text="DitsiTest"></asp:Label></rd:rdiv>

    And this code in the control, what should i change?

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using RoundedDiv;
    namespace RoundedDiv
        [ToolboxData("<{0}:rdiv runat=server></{0}:rdiv>")]    
        public class rdiv : WebControl
            protected string htmlFieldName;
            [DefaultValue("Testing text")]
            public string Text
                    String s = (String)ViewState["Text"];
                    return ((s == null) ? "[" + this.ID + "]" : s);
                    ViewState["Text"] = value;
            protected override void RenderContents(HtmlTextWriter output)
                    // No need for ViewState
                    this.EnableViewState = false;
                    // Should the control be visible?
                    if (this.Visible == true)
                        // Yes. Render the html.
                catch (Exception ex)
                    // Something bad happened. Let's tell the user what that was.
                    output.Write("Error building Roundeddiv:<br>");
            protected void BuildRoundedDiv(HtmlTextWriter output)
                output.Write("<div class='bl'><div class='br'><div class='tl'><div class='tr'>");


    Thursday, November 26, 2009 4:32 AM


  • User-16411453 posted

    The div tag is a just a panel control. You have to make the panel control first in code, so that it is an object.

    panel_parent panal = new Panel


    panel_child panel = new Panel


    using <div><div> just writes text to the render engine, and does not create an object to work with

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 29, 2009 11:09 PM

All replies