组件开发中常用的属性
2007-05-22 09:45
337 查看
DefaultEvent( "ClickNext" ):指定组件的默认事件
DefaultProperty( "NextText" ):指定组件的默认属性
Bindable(true or false):指定属性是否通常用于绑定
Category( "Appearance" ):指定其属性或事件将显示在可视化设计器中的类别
DefaultValue( typeof( Color ) , "" ):指定属性的默认值
Description( "The background color"):指定属性或事件的说明
TypeConverter(typeof( WebColorConverter )):指定用作此特性所绑定到的对象的转换器的类型
Browsable(true or false):指定一个属性或事件是否应显示在“属性”窗口中
DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden ):指定在设计时序列化组件上的属性时所使用的持久性类型
==========================================================================
简单控件 事件
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);
}
}
}
DefaultProperty( "NextText" ):指定组件的默认属性
Bindable(true or false):指定属性是否通常用于绑定
Category( "Appearance" ):指定其属性或事件将显示在可视化设计器中的类别
DefaultValue( typeof( Color ) , "" ):指定属性的默认值
Description( "The background color"):指定属性或事件的说明
TypeConverter(typeof( WebColorConverter )):指定用作此特性所绑定到的对象的转换器的类型
Browsable(true or false):指定一个属性或事件是否应显示在“属性”窗口中
DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden ):指定在设计时序列化组件上的属性时所使用的持久性类型
==========================================================================
简单控件 事件
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);
}
}
}
相关文章推荐
- iOS开发:接触IOS的第一个组件UILabel (常用属性)
- Android应用开发——界面开发之常用组件的属性介绍
- iOS App开发中UITextField组件的常用属性小结
- iOS开发总结之UILabel常用属性
- Android开发——控件TextView的用法(常用属性)
- React Native开发中常用三方组件库
- 组件开发之Asp.net服务器控件Collection[集合]属性的设计时支持--编辑、保存
- 30组常用前端开发组件库,前端组件收集整理列表
- android手机开发常用开源组件
- C#使用Xamarin开发可移植移动应用终章(11.获取设备信息与常用组件,开源一个可开发模版.)
- 属性-主要应用于组件开发
- android开发---常用属性2
- 常用Android开发组件之按钮类组件
- 【iOS开发】ScrollView的一些常用属性
- Form开发中组件控制的几个常用方法
- iOS开发之UITextField常用属性设置
- web 开发:CSS3 常用属性——速查手册!
- .net开发中常用的第三方组件
- IOS开发中属性常用的关键字以及作用 内存管理
- 【Android 开发】:Android布局中的几种常用属性