zoukankan      html  css  js  c++  java
  • 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
        }

    }


  • 相关阅读:
    总结c#和javascript中常见的相关的"空"
    javascript从未如此流行(JavaScript has never been so popular .)
    解决ajax调用中ie的缓存问题
    《.NET框架程序设计》第5章 基元类型、引用类型与值类型
    DataTable复制到新的DataTable并筛选
    《.NET框架程序设计》第1章 .NET开发平台体系架构 读后感
    《.NET框架程序设计》第4章 类型基础 读后感
    《.NET框架程序设计》第2章 第3章 读后感
    《道德经》程序员版第四十二章
    数据库设计总结
  • 原文地址:https://www.cnblogs.com/di305449473/p/1245800.html
Copyright © 2011-2022 走看看