首页 > 编程 > .NET > 正文

ASP.NET自定义Web服务器控件之Button控件

2024-07-10 12:48:16
字体:
来源:转载
供稿:网友

本文实例讲述了ASP.NET自定义Web服务器控件之Button控件实现方法。。具体实现方法如下:

代码如下: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; 
 
//自定义web服务器button 
namespace MyControls 

    [DefaultProperty("Text")] 
    [ToolboxData("<{0}:MyButton runat=server></{0}:MyButton>")] 
    public class MyButton : WebControl,IPostBackEventHandler 
    { 
        [Bindable(true)] 
        [Category("Appearance")] 
        [DefaultValue("")] 
        [Localizable(true)] 
        public string Text 
        { 
            get 
            { 
                String s = (String)ViewState["Text"]; 
                return ((s == null) ? String.Empty : s); 
            } 
 
            set 
            { 
                ViewState["Text"] = value; 
            } 
        } 
 
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]//生成属性时,按属性内部内容生成(例如在此控件里面(Size-Height,Size_Width)) 
        //[PersistenceMode(PersistenceMode.InnerProperty)]//以子标签的形式显示(例如<Size Width="" Height=""/>) 
        public Size Size 
        { 
            get 
            { 
                if (ViewState["Size"] == null) { 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表