• asp.net控件开发基础(3)


    类型可供选择的按钮自定义控件
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web.UI;
    using System.ComponentModel;

    namespace ComponentControl
    {
        
    public class Ctrl5:Control,IPostBackEventHandler
        
    {
            
    private static readonly object obj = new object();

            [Description(
    "按钮显示的类型")]
            
    public BtnType ButtonType
            
    {
                
    get return ViewState["ButtonType"== null ? BtnType.Button : (BtnType)ViewState["ButtonType"]; }
                
    set { ViewState["ButtonType"= value; }
            }


            
    //事件
            public virtual event EventHandler Click
            
    {
                add 
    {
                    Events.AddHandler(obj, value);
                }

                remove
                
    {
                    Events.RemoveHandler(obj, value);
                }

            }


            
    //控件重写
            protected override void Render(HtmlTextWriter writer)
            
    {
                
    if (ButtonType == BtnType.Button)
                    writer.Write(
    "<input type=submit name=" + this.UniqueID + " value=Button />");
                
    else if (ButtonType == BtnType.LinkButton)
                    writer.Write(
    "<a href="+Page.GetPostBackClientHyperlink(this,"")+">Button</a>");
            }


            
    IPostBackEventHandler 成员
        }


        
    //按钮类型枚举
        public enum BtnType
        

            Button,
            LinkButton
        }

    }


  • 相关阅读:
    jsp servlet table 集合list 数据 绑定
    Linux下“/”和“~”的区别
    android 百度地图 定位获取位置失败 62错误
    PostgreSQL 空间数据类型point、 line等
    PostgreSQL 与 PostGIS
    MySQL及navicat for mysql中文乱码
    eclipse报错:Multiple annotations found at this line:
    Multiple markers at this line
    css中绝对定位和相对定位的区别
    关于display的属性:block和inline-block以及inline的区别,float相关说明
  • 原文地址:https://www.cnblogs.com/di305449473/p/1245800.html
Copyright © 2020-2023  润新知