locked
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
    {
        [DefaultProperty("Text")]
        [ToolboxData("<{0}:rdiv runat=server></{0}:rdiv>")]    
        public class rdiv : WebControl
        {
            protected string htmlFieldName;
    
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("Testing text")]
            [Localizable(true)]
            public string Text
            {
                get
                {                
                    String s = (String)ViewState["Text"];
                    return ((s == null) ? "[" + this.ID + "]" : s);
                }
    
                set
                {
                    ViewState["Text"] = value;
                }
            }
    
    
            protected override void RenderContents(HtmlTextWriter output)
            {
                try
                {
                    // No need for ViewState
                    this.EnableViewState = false;
    
                    // Should the control be visible?
                    if (this.Visible == true)
                    {
                        // Yes. Render the html.
                        BuildRoundedDiv(output);
                    }
                }
                catch (Exception ex)
                {
                    // Something bad happened. Let's tell the user what that was.
                    output.Write("Error building Roundeddiv:<br>");
                    output.Write(ex.Message);
                }
                output.Write(Text);
            }
    
            protected void BuildRoundedDiv(HtmlTextWriter output)
            {
                output.Write("<div class='bl'><div class='br'><div class='tl'><div class='tr'>");
                output.Write(Text);
                output.Write("</div></div></div></div>");
            }
        }
    }
    


     

    Thursday, November 26, 2009 4:32 AM

Answers

  • 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

    controls.Add(panel_parent)

    panel_child panel = new Panel

    panel_parent.controls.add(panel_child)

    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