自定义ASP.NET容器控件 [英] Custom ASP.NET Container Control

查看:326
本文介绍了自定义ASP.NET容器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图创建工作完全一样,除了由少数div的包围,这样创造一个圆角盒的外观面板控件的自定义控制。我一直没能找到如何做到这一点像样的例子。

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 able to find a decent example of how to do this.

我需要能够把文本和控件的控件内部访问的情况下直接引用面板(确切的方式Panel控件的作品)。

I need to be able to place text and controls inside the control and access it directly without referencing the panel (exactly the way the Panel control works).

有没有人有任何的例子?

Does anyone have any examples of this?

推荐答案

有两种方法可以做到这一点。一是实现你的控制作INamingContainer,它需要很多的努力。

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

另一种方法是从面板继承,并重写对RenderBeginTag和RenderEndTag方法来添加自定义标记。这很容易。

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");                     
    }
}

这篇关于自定义ASP.NET容器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆