Coustom web control 自定义控件
简单控件 事件
EventManager
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace MyControls
{
/**//// <summary>
/// Summary description for MyEventManager.
/// </summary>
[DefaultEvent("NextClick"),DefaultProperty("text")]
public class MyEventManager : System.Web.UI.WebControls.WebControl,IPostBackEventHandler
{
public event EventHandler NextClick;
public event EventHandler PreClick;
[Bindable(true),Category("Behavior"),DefaultValue(""),Description("text ")]
public string text
{
get
{
return ( (string)ViewState["text"] == null )? string.Empty:(string)ViewState["text"] ;
}
set
{
ViewState["text"] = value;
}
}
protected virtual void OnNextClick(EventArgs e)
{
if(NextClick != null)
{
NextClick(this,EventArgs.Empty);
}
}
protected virtual void OnPreClick(EventArgs e)
{
if(PreClick != null)
{
PreClick(this,EventArgs.Empty);
}
}
void IPostBackEventHandler.RaisePostBackEvent(string EventArguments)
{
if( EventArguments =="Pre" )
{
OnPreClick(EventArgs.Empty);
Page.Trace.Warn("Pre Button Click");
}
else
{
OnNextClick(EventArgs.Empty);
Page.Trace.Warn("Next Button Click");
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
protected override void Render(HtmlTextWriter output)
{
//output.Write(Text);
this.Attributes.AddAttributes(output);
output.AddAttribute(HtmlTextWriterAttribute.Onclick,Page.GetPostBackEventReference(this,"Pre"));
output.AddAttribute("language","javascript");
output.RenderBeginTag(HtmlTextWriterTag.Button);
output.Write("Pre");
output.RenderEndTag();
output.AddAttribute(HtmlTextWriterAttribute.Onclick,Page.GetPostBackEventReference(this,"Next"));
output.AddAttribute("language","javascript");
output.RenderBeginTag(HtmlTextWriterTag.Button);
output.Write("Next");
output.RenderEndTag();
base.Render(output);
}
}
}
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace MyControls
{
/**//// <summary>
/// Summary description for MyEventManager.
/// </summary>
[DefaultEvent("NextClick"),DefaultProperty("text")]
public class MyEventManager : System.Web.UI.WebControls.WebControl,IPostBackEventHandler
{
public event EventHandler NextClick;
public event EventHandler PreClick;
[Bindable(true),Category("Behavior"),DefaultValue(""),Description("text ")]
public string text
{
get
{
return ( (string)ViewState["text"] == null )? string.Empty:(string)ViewState["text"] ;
}
set
{
ViewState["text"] = value;
}
}
protected virtual void OnNextClick(EventArgs e)
{
if(NextClick != null)
{
NextClick(this,EventArgs.Empty);
}
}
protected virtual void OnPreClick(EventArgs e)
{
if(PreClick != null)
{
PreClick(this,EventArgs.Empty);
}
}
void IPostBackEventHandler.RaisePostBackEvent(string EventArguments)
{
if( EventArguments =="Pre" )
{
OnPreClick(EventArgs.Empty);
Page.Trace.Warn("Pre Button Click");
}
else
{
OnNextClick(EventArgs.Empty);
Page.Trace.Warn("Next Button Click");
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
protected override void Render(HtmlTextWriter output)
{
//output.Write(Text);
this.Attributes.AddAttributes(output);
output.AddAttribute(HtmlTextWriterAttribute.Onclick,Page.GetPostBackEventReference(this,"Pre"));
output.AddAttribute("language","javascript");
output.RenderBeginTag(HtmlTextWriterTag.Button);
output.Write("Pre");
output.RenderEndTag();
output.AddAttribute(HtmlTextWriterAttribute.Onclick,Page.GetPostBackEventReference(this,"Next"));
output.AddAttribute("language","javascript");
output.RenderBeginTag(HtmlTextWriterTag.Button);
output.Write("Next");
output.RenderEndTag();
base.Render(output);
}
}
}