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")]程式集名+資源名