| using System; using System.ComponentModel; using System.Security.Permissions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace CustomerControls { [ AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), ToolboxData("<{0}:IndexButton runat=\"server\"> </{0}:IndexButton>") ] public class IndexButton : Button { private int indexValue; [ Bindable(true), Category("Behavior"), DefaultValue(0), Description("The index stored in control state.") ] public int Index { get { return indexValue; } set { indexValue = value; } } [ Bindable(true), Category("Behavior"), DefaultValue(0), Description("The index stored in view state.") ] public int IndexInViewState { get { object obj = ViewState["IndexInViewState"]; return (obj == null) ? 0 : (int)obj; } set { ViewState["IndexInViewState"] = value; } } protected override void OnInit(EventArgs e) { base.OnInit(e); Page.RegisterRequiresControlState(this); } protected override object SaveControlState() { //调用基类的方法,从基类得到控件状态的基值 //如果indexValue不等于并且基类的控件状态不为null //使用Pair作为便利的数据结构来高效保存(和在LoadControlState方法中还原) //由两部分组成的控件状态 object obj = base.SaveControlState(); if (indexValue != 0) { if (obj != null) { return new Pair(obj, indexValue); } else { return (indexValue); } } else { return obj; } } protected override void LoadControlState(object state) { if (state != null) { Pair p = state as Pair; if (p != null) { base.LoadControlState(p.First); indexValue = (int)p.Second; } else { if (state is int) { indexValue = (int)state; } else { base.LoadControlState(state); } } } } } } |
![]() | asp.net mvc中的拦截器 | 12-02 |
![]() | asp.net使用Mysql乱码处理 | 11-19 |
![]() | ASP.NET中Cookie的使用 | 11-10 |
![]() | 在Asp.net MVC中使用Repeater | 10-27 |
![]() | 如何对ASP.NET进行性能优化 | 09-24 |
![]() | 把网页中的电话号码生成图片的ASP程序 | 11-23 |
![]() | 通过避免下列10个常见ASP.NET缺陷使网站平 | 06-03 |
![]() | Asp.Net、Ado.net 数据库编程超级攻略 | 06-03 |