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