婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > ASP.NET自定義Web服務(wù)器控件之Button控件

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

熱門(mén)標(biāo)簽:t3出行地圖標(biāo)注怎么做 外呼電銷(xiāo)機(jī)器人軟件 河北網(wǎng)絡(luò)回?fù)芡夂粝到y(tǒng) 400電話辦理最優(yōu)質(zhì) 400免費(fèi)電話怎么辦理 威海電銷(xiāo) 關(guān)于宗地圖標(biāo)注技術(shù)規(guī)范 寧夏機(jī)器人電銷(xiāo) 河南語(yǔ)音外呼系統(tǒng)公司

本文實(shí)例講述了ASP.NET自定義Web服務(wù)器控件之Button控件實(shí)現(xiàn)方法。分享給大家供大家參考。具體實(shí)現(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)]//生成屬性時(shí),按屬性?xún)?nèi)部?jī)?nèi)容生成(例如在此控件里面(Size-Height,Size_Width)) 
        //[PersistenceMode(PersistenceMode.InnerProperty)]//以子標(biāo)簽的形式顯示(例如Size Width="" Height=""/>) 
        public Size Size 
        { 
            get 
            { 
                if (ViewState["Size"] == null) { 
                    ViewState["Size"] = new Size(); 
                } 
                return (Size)ViewState["Size"]; 
            } 
 
            set 
            { 
                ViewState["Size"] = value; 
            } 
        } 
        //定義控件的標(biāo)簽形式 
        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ā)事件必須有的一個(gè)屬性 
            base.OnInit(e); 
        } 
        //打印當(dāng)前控件的內(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="我是一個(gè)單獨(dú)的提交按鈕(自定義服務(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ù)器控件的點(diǎn)擊事件"); 
    } 
}

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

您可能感興趣的文章:
  • ASP.NET服務(wù)器端控件RadioButtonList,DropDownList,CheckBoxList的取值、賦值用法
  • asp.net Page.EnableEventValidation 屬性驗(yàn)證服務(wù)器控件的回發(fā)和回調(diào)事件出現(xiàn)的錯(cuò)誤
  • jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶(hù)端HTML標(biāo)簽后的value和text值
  • asp.net 服務(wù)器控件的 ID,ClientID,UniqueID 的區(qū)別
  • asp.net下使用Request.From獲取非服務(wù)器控件的值的方法
  • jQuery生成asp.net服務(wù)器控件的代碼
  • ASP.NET 動(dòng)態(tài)寫(xiě)入服務(wù)器端控件
  • asp.net Page.Controls對(duì)象(找到所有服務(wù)器控件)
  • Asp.Net使用服務(wù)器控件Image/ImageButton顯示本地圖片的方法

標(biāo)簽:淮北 池州 吉林 賀州 廣元 樂(lè)山 咸寧 固原

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET自定義Web服務(wù)器控件之Button控件》,本文關(guān)鍵詞  ASP.NET,自定義,Web,服務(wù)器,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET自定義Web服務(wù)器控件之Button控件》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于ASP.NET自定義Web服務(wù)器控件之Button控件的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 教育| 合水县| 新沂市| 沁源县| 读书| 莲花县| 七台河市| 崇仁县| 分宜县| 平阳县| 册亨县| 大厂| 罗源县| 于田县| 梅河口市| 泉州市| 泸州市| 都江堰市| 观塘区| 衢州市| 偃师市| 从化市| 循化| 东源县| 梅河口市| 郎溪县| 泸定县| 全南县| 平安县| 阳山县| 繁昌县| 拜城县| 盐亭县| 两当县| 炎陵县| 观塘区| 蒲江县| 京山县| 开江县| 沙湾县| 丰城市|