Type: using system;
Using system. Collections. Generic;
Using system. text;
Using system. Web. UI;
Using system. componentmodel;
Namespace componentcontrol
{
Public class ctrl5: control, ipostbackeventhandler
{
Private Static readonly object OBJ = new object ();
[Description ("button display type")]
Public btntype buttontype
{
Get {return viewstate ["buttontype"] = NULL? Btntype. Button: (btntype) viewstate ["buttontype"];}
Set {viewstate ["buttontype"] = value ;}
}
// Event
Public Virtual Event eventhandler click
{
Add {
Events. addhandler (OBJ, value );
}
Remove
{
Events. removehandler (OBJ, value );
}
}
// Control Rewriting
Protected override void render (htmltextwriter writer)
{
If (buttontype = btntype. button)
Writer. Write ("<input type = submit name =" + this. uniqueid + "value = button/> ");
Else if (buttontype = btntype. linkbutton)
Writer. Write ("<a href =" + Page. getpostbackclienthyperlink (this, "") + "> button </a> ");
}
Ipostbackeventhandler member # region ipostbackeventhandler Member
Public void raisepostbackevent (string eventargument)
{
Eventhandler child = (eventhandler) events [OBJ];
If (child! = NULL)
Child (this, eventargs. Empty );
}
# Endregion
}
// Button type Enumeration
Public Enum btntype
{
Button,
Linkbutton
}
}