Source: http://blog.csdn.net/caoxicao
Author: caoxi grass
Reprinted please indicate the source
Htmltextwriter
The parameter values of various htmltextwriter methods are as follows: htmltextwritertag, htmltextwriterattribute, and htmltextwriterstyle. These enumerations list the public signature, attribute, and CSS style attribute of html4.0. Many methods in htmltextwriter are overloaded. strings or enumerated values can be transmitted as a parameter.
-----------------------------------------
Delegation and events
I have been deeply influenced by the delegation and events in C #. I think that the delegate is delegate, and the event is event. Haha. The original ASP. NET
In eventhandler is the so-called delegate. Dizzy!
The event model in. NET Framework is based on an event delegate that connects the event to the event handler. Two elements are required for triggering an event:
Class that stores event data. This class must be derived from the base class eventargs.
The delegate to the method that provides the response to the event.
If the event does not generate data, the base class eventargs of the event data object and the predefined eventhandler of the event Delegate are used.
For example, public delegate void eventhandler (Object sender, eventargs E );
This is a declaration of delegation that does not contain data events. eventhandler is a predefined event Delegate, sender is the object that triggers the event, and E is the event data object that does not contain data, eventargs is the base class of the class that contains event data.
----------------------------------------------
Composite Control
The ensurechildcontrols () method is to confirm that the current control has a child control. If not, create a new one.
The composite control can choose whether to expose the child control as a property, and which attributes and events of the Child control are exposed as top-level properties and events.
The text attribute of the button sub-control is published as the buttontext attribute as follows.
Public String buttontext {
Get {
Ensurechildcontrols ();
Return _ button. text;
}
Set {
Ensurechildcontrols ();
_ Button. Text = value;
}
}
-----------------------------------------
Event Optimization
C # provides "attribute style event Declaration"
Basic Format:
Public event [Delegate type] [event name]
{
Add {....}
Remove {....}
}
Use this "event model" to create event delegation. The control class definesKeyUsed to store and retrieve event delegation in eventhandler.
For example, the following code showsKey.
Private Static readonly object eventlogon = new object ();
KeyIs static (shared among all instances of the control), so it is only created once for each event. The following code shows C #Attribute Model of an eventThis is a declaration of a logon event.
Public event eventhandler logon {
Add {
Events. addhandler (eventlogon, value );
}
Remove {
Events. removehandler (eventlogon, value );
}
}
Finally, let's take a look at the implementation of the On <eventname> (event processing) method. This method is mainly used to trigger events. When usingAttribute Model of an eventYou must retrieve the delegate from the eventhandlist and convert it to the event Delegate type before calling the additional handler.
Protected virtual void onlogon (eventargs e ){
Eventhandler logonhandler = (eventhandler) events [eventlogon];
If (logonhandler! = NULL ){
Logonhandler (this, e );
}
}
Note: Here, logonhandler is already a delegate-type instance, so Logon
Note: system. componentmodel. eventhandlerlist provides a simple delegation list.