Reading Notes --asp.net 2.0 Server Components and controls advanced programming 0629

Source: Internet
Author: User

Composite Control
Inherit compositecontrol
Layout
Implement the inamingcontainer Interface
Inamingcontainer is a tag interface with no attribute Methods
Provides a protected virtual method to initialize the control.
Add control container. Controls. Add
Provides a protected virtual method to add the Container Control addcontainer (container con)
Use ensurechildcontrols to check bool childcontrolscreated to avoid multiple component creation.
After creating the child control, set childcontrolscreated to true;
Tagkey to determine the HTML elements to contain the entire custom control
This control is rewritten
Get (return htmltextwritertag. Table ;)
Rendercontrets (htmltextwriter writer)

Writer. renderbegintag ()
Rendercontainer (container, writer)
Rendercontainer (container, writer)
Writer. renderendtag ()

Sub-Control Properties

Public Virtual string paytext
{
Get
{
Ensurechildcontrols ();
Return paylabel. text;
}
Set
{
Ensurechildcontrols ();
Paylabel. Text = value;
}
}

Subcontrol triggers command event
Private Static readonly objectivecommandeventkey = new object ();

Public event commandeventhandle command
{
Add {events. addhandler (commandeventkey, value );}
Remove {event. removehandler (commandeventkey, value );}
}

Protected virtual void oncommand (commandeventarg E)
{
Commandeventhandler handler = event [commandeventkey] As commandeventhandler;
If (handler! = NULL) handler (this E );
Raisebubblerevent (this, e );
}

The commandeventargs event data class exposes the commandname and commandargument attributes to maintain the command name and command parameters.
Send commandeventargs to the raisebubblerevent method, which promotes the sub-control event to the parent control event.

Potected virtual void raisepostbackevent (string evnentargument)
{
...
Commandeventargs E = new commandeventargs (commandname, commandargument );
Oncommand (E );
}

The control class exposes the onbubbleevent method, which must be overwritten in accordance with the control.
Protected override bool onbubbleevent (Object source, eventargs ARGs)
First, check whether the command event is captured.
Commandeventargs Ce = Arg as commandeventargs;

If (Ce! = NULL & Ce. commandname = "validatecreditcard ")
This process can obtain the sub-control information, construct the event data class, and trigger the event
Compositecontrol provides the required features
1) rewrite the controls set.
2) Implement inaminginterface
3) override the databind Method
4) Implement the icompositecontroldesigneraccessor interface. This interface defines a recreatechildcontrols Method
5) before implementing render, when in design mode, you can override the render method to call the ensurechildcontrols method.

Override the controls set
Public override controlcollection Control
{
Get {
Ensurechildcontrol ();
Return base. controls;
}
}

Inamingcontainer sets a unique value for the clientid and uniqueid attributes
The child control inherits the namingcontainer attribute of the control class. This attribute points to the parent control that implements the inamingcontainer interface.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.