ASP.Net自訂控制項開發(帶資源)

來源:互聯網
上載者:User

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;using System.Drawing;namespace Mytext{    [DefaultProperty("Text")]    [ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]    public class SefTextBox:TextBox    {        [Bindable(true)]        [Category("Appearance")]        [DefaultValue("")]        [Localizable(true)]        public EnumType Datatype        {            get;            set;        }        [Bindable(true)]        [DefaultValue("提示")]        [Localizable(true)]        public string TipMsg        {            get;            set;        }        public string Text        {            get            {                String s = (String)ViewState["Text"];                return ((s == null) ? "[" + this.ID + "]" : s);            }            set            {                ViewState["Text"] = value;            }        }        protected override void OnPreRender(EventArgs e)        {            base.OnPreRender(e);            Attributes.Add("tipmsg", TipMsg);            Attributes.Add("onclick", "msg()");            var txtValue = this.ID+this.Text;            string starPath = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Mytext.SefTextBox.gif");  程式集名+資源名            this.Style.Add(HtmlTextWriterStyle.BackgroundImage,  starPath );           // Attributes.Add("style", " background-image:url('SefTextBox.gif')");            HttpContext.Current.Response.Write("<script>var a='" + txtValue + "';function msg(){alert(a)}</script>");        }        protected override void AddAttributesToRender(HtmlTextWriter writer)        {            base.AddAttributesToRender(writer);        }        public enum EnumType        {            None,            Int,            Num,            Num2,            Num4,                 Date,                     Email,        }    }}

AssemblyInfo.cs檔案

using System.Reflection;using System.Runtime.CompilerServices;using System.Runtime.InteropServices;using System.Web.UI;// 有關程式集的常規資訊通過以下// 特性集控制。更改這些特性值可修改// 與程式集關聯的資訊。[assembly: AssemblyTitle("Mytext")][assembly: AssemblyDescription("")][assembly: AssemblyConfiguration("")][assembly: AssemblyCompany("")][assembly: AssemblyProduct("Mytext")][assembly: AssemblyCopyright("Copyright   2011")][assembly: AssemblyTrademark("")][assembly: AssemblyCulture("")]// 將 ComVisible 設定為 false 使此程式集中的類型// 對 COM 組件不可見。如果需要從 COM 訪問此程式集中的類型,// 則將該類型上的 ComVisible 特性設定為 true。[assembly: ComVisible(false)]// 如果此項目向 COM 公開,則下列 GUID 用於類型庫的 ID[assembly: Guid("6125c523-9289-4139-96dd-73a27bee4086")]// 程式集的版本資訊由下面四個值組成:////      主要版本//      次版本//      組建號//      修訂編號//[assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")][assembly: WebResource("Mytext.SefTextBox.gif", "image/jpg")]程式集名+資源名

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.