最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET自定義Web服務(wù)器控件之Button控件

 更新時間:2014年11月25日 09:03:06   投稿:shichen2014  
這篇文章主要介紹了ASP.NET自定義Web服務(wù)器控件之Button控件,詳細講述了Button控件的實現(xiàn)代碼、前臺頁面的調(diào)用以及對應(yīng)的事件響應(yīng)代碼,具有很好的參考借鑒價值,需要的朋友可以參考下

本文實例講述了ASP.NET自定義Web服務(wù)器控件之Button控件實現(xiàn)方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

復(fù)制代碼 代碼如下:
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服務(wù)器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)]//生成屬性時,按屬性內(nèi)部內(nèi)容生成(例如在此控件里面(Size-Height,Size_Width)) 
        //[PersistenceMode(PersistenceMode.InnerProperty)]//以子標簽的形式顯示(例如<Size Width="" Height=""/>) 
        public Size Size 
        { 
            get 
            { 
                if (ViewState["Size"] == null) { 
                    ViewState["Size"] = new Size(); 
                } 
                return (Size)ViewState["Size"]; 
            } 
 
            set 
            { 
                ViewState["Size"] = value; 
            } 
        } 
        //定義控件的標簽形式 
        protected override HtmlTextWriterTag TagKey 
        { 
            get 
            { 
                return HtmlTextWriterTag.Input; 
            } 
        } 
 
        //初始化 
        protected override void OnInit(EventArgs e) 
        { 
            this.Style.Add("width", Size.Width + "px"); 
            this.Style.Add("height", Size.Height + "px"); 
            this.Attributes.Add("type", "submit"); //提交按鈕 
            this.Attributes.Add("value",Text); 
            this.Attributes.Add("name",this.UniqueID);//回發(fā)事件必須有的一個屬性 
            base.OnInit(e); 
        } 
        //打印當前控件的內(nèi)容 
        protected override void RenderContents(HtmlTextWriter output) 
        { 
            //output.Write(Text); 
        } 
         
        public delegate void ClickHandle(); 
        private object key=new object(); 
        public event ClickHandle Click { 
            add { 
                this.Events.AddHandler(key,value); 
            } 
            remove { 
                this.Events.RemoveHandler(key, value); 
            } 
        } 
        //按鈕的回發(fā)事件 
        public void RaisePostBackEvent(string eventArgument) 
        { 
            ClickHandle handle = (ClickHandle)base.Events[key]; 
            if (handle != null) { 
                handle(); 
            } 
        } 
    } 
}

復(fù)制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<%@ Register assembly="MyControls" namespace="MyControls" tagprefix="cc1" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <!--自定義服務(wù)器按鈕控件--> 
        <cc1:MyButton ID="MyButton1" Size-Height="30" Size-Width="290" OnClick="btnSubmit" Text="我是一個單獨的提交按鈕(自定義服務(wù)器)" runat="server" /> 
    </div> 
  
     
    </form> 
 
</body> 
</html>

復(fù)制代碼 代碼如下:
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
 
public partial class _Default : System.Web.UI.Page 

    protected void Page_Load(object sender, EventArgs e) 
    { 
 
    } 
    //自定義服務(wù)器控件 
    protected void btnSubmit() { 
        Response.Write("我是自定義服務(wù)器控件的點擊事件"); 
    } 
}

希望本文所述對大家的asp.net程序設(shè)計有所幫助。

相關(guān)文章

最新評論

凤台县| 巨鹿县| 金沙县| 和顺县| 武定县| 黎城县| 乌兰察布市| 红原县| 福鼎市| 固阳县| 靖安县| 旌德县| 安岳县| 尼木县| 平远县| 云浮市| 鄱阳县| 醴陵市| 辽源市| 辽阳县| 墨脱县| 长白| 桑日县| 临邑县| 廉江市| 象州县| 灵武市| 永泰县| 天峨县| 临西县| 济南市| 南平市| 银川市| 哈尔滨市| 安图县| 漳浦县| 邢台市| 汤阴县| 无棣县| 吉水县| 太和县|