Custom ASP.NET Container Control

前端 未结 8 1868
醉话见心
醉话见心 2020-12-14 20:50

I\'ve been trying to create a custom control that works exactly like the Panel control except surrounded by a few divs and such to create a rounded box look. I haven\'t been

相关标签:
8条回答
  • 2020-12-14 21:28

    There is two ways to do this. One is to implement INamingContainer on your control, and it takes a lot of effort.

    The other way is to inherit from Panel, and override the RenderBeginTag and RenderEndTag methods to add your custom markup. This is easy.

    public class RoundedCornersPanel : System.Web.UI.WebControls.Panel
    {
        public override RenderBeginTag (HtmlTextWriter writer)
        {
            writer.Write("Your rounded corner opening markup");
            base.RenderBeginTag(writer);
        }
    
        public override RenderEndTag (HtmlTextWriter writer)
        {
            base.RenderEndTag(writer);
            writer.Write("Your rounded corner closing markup");                     
        }
    }
    
    0 讨论(0)
  • 2020-12-14 21:28
    public class myCustomPanel : Panel
    {
        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "top_left_corner");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
                base.RenderBeginTag(writer);
        }
    
        public override void RenderEndTag(HtmlTextWriter writer)
        {
                base.RenderEndTag(writer);
            writer.RenderEndTag();
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题