本文发表在 rolia.net 枫下论坛using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace MyWebControls2
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebButton runat=server></{0}:WebButton>")]
public class WebButton : System.Web.UI.WebControls.Button
{
private string displayString;
public WebButton( )
{
this.Text = "Button";
InitValues();
}
public WebButton(string displayString)
{
this.displayString = displayString;
InitValues();
}
private void InitValues( )
{
if (ViewState["Count"] == null)
ViewState["Count"] = 0;
this.Text = "Click me";
}
private void InitializeComponent()
{
}
public int Count
{
get
{
return (int) ViewState["Count"];
}
set
{
ViewState["Count"] = value;
}
}
protected override void OnClick(EventArgs e)
{
ViewState["Count"] = ((int)ViewState["Count"]) + 1;
this.Text = ViewState["Count"] + " " + displayString;
base.OnClick(e);
}
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace MyWebControls2
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebButton runat=server></{0}:WebButton>")]
public class WebButton : System.Web.UI.WebControls.Button
{
private string displayString;
public WebButton( )
{
this.Text = "Button";
InitValues();
}
public WebButton(string displayString)
{
this.displayString = displayString;
InitValues();
}
private void InitValues( )
{
if (ViewState["Count"] == null)
ViewState["Count"] = 0;
this.Text = "Click me";
}
private void InitializeComponent()
{
}
public int Count
{
get
{
return (int) ViewState["Count"];
}
set
{
ViewState["Count"] = value;
}
}
protected override void OnClick(EventArgs e)
{
ViewState["Count"] = ((int)ViewState["Count"]) + 1;
this.Text = ViewState["Count"] + " " + displayString;
base.OnClick(e);
}
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net