The original name of compositecontrol development is the development of composite controls. I think there are still some routines that can be followed for the development of controls.
Define the server-side properties of the control
Code
/// <Summary>
/// Script path
/// </Summary>
[Bindable ( True ), Browsable ( True ), Defaultvalue ( " ../JS/SG/sg_autofilter.js " )]
Public String Scriptpath
{
Get
{
If (Viewstate [ " Scriptpath " ] ! = Null )
Return ( String ) Viewstate [ " Scriptpath " ];
Return " ../JS/SG/sg_autofilter.js " ;
}
Set
{
Viewstate [ " Scriptpath " ] = Value;
}
}
Define the start label of the server control
Code
Protected OverrideHtmltextwritertag tagkey
{
Get
{
ReturnHtmltextwritertag. div;
}
}
Add style attributes to the start tag of the server control
Code
Protected Override VoidAddattributestorender (htmltextwriter writer)
{
Writer. addattribute (htmltextwriterattribute. style,String. Format ("Width: {0} PX", Width ));
}
Add sub-controls in the tag
Code
Protected Override Void Createchildcontrols ()
{
Private Htmlinputtext txttargetcontrol = New Htmlinputtext ();
Private Hiddenfield txttargetcontrolvalue = New Hiddenfield ();
Private System. Web. UI. webcontrols. Image imgpopup;
Controls. Clear ();
// Txttargetcontrol = new htmlinputtext ();
Txttargetcontrol. ID = " Txttargetcontrol " ;
Txttargetcontrol. Value = This . Text;
Txttargetcontrol. Attributes. Add ( " AutoComplete " , " Off " );
Txttargetcontrol. Attributes. Add ( " Style " , String . Format ( " Border: 0px solid #9 abfdc; width: {0} PX " ,( This . Width - 17 ). Tostring ()));
Imgpopup = New System. Web. UI. webcontrols. Image ();
Imgpopup. ID = " Imgpopup " ;
Imgpopup. style. Add (htmltextwriterstyle. cursor, " Hand " );
Imgpopup. Attributes. Add ( " Title " , " After selecting a company, click this button to close the company selection box! " );
If (Popupimageurl = "" )
Imgpopup. imageurl = Page. clientscript. getwebresourceurl ( This . GetType (), " Sagacity.controls.popup.gif " );
Else
Imgpopup. imageurl = Popupimageurl;
// Txttargetcontrolvalue = new hiddenfield ();
Txttargetcontrolvalue. ID = " Txttargetcontrolvalue " ;
Txttargetcontrolvalue. Value = This . Value;
Controls. Add (txttargetcontrol );
Controls. Add (txttargetcontrolvalue );
Controls. Add (imgpopup );
Childcontrolscreated= True;
}
Add style attributes to controls in the tag
Code
Protected Override Void Rendercontents (htmltextwriter writer)
{
Writer. addattriding (htmltextwriterattribute. cellpadding, " 0 " );
Writer. addattriing (htmltextwriterattribute. cellspacing, " 0 " );
Writer. addattribute (htmltextwriterattribute. style, String . Format ( " Border: 1px solid #9 abfdc; width: {0} PX " , This . Width ));
Writer. renderbegintag (htmltextwritertag. Table );
Writer. renderbegintag (htmltextwritertag. tr );
Writer. addattriign (htmltextwriterattribute. Align, " Right " );
Writer. addstyleattribute (htmltextwriterstyle. paddingright, " 0px " );
Writer. renderbegintag (htmltextwritertag. TD );
Txttargetcontrol. rendercontrol (writer );
Txttargetcontrolvalue. rendercontrol (writer );
Writer. renderendtag ();
Writer. addattriign (htmltextwriterattribute. Align, " Left " );
Writer. addstyleattribute (htmltextwriterstyle. paddingleft, " 0px " );
Writer. addstyleattribute (htmltextwriterstyle. paddingright, " 0px " );
Writer. addstyleattribute (htmltextwriterstyle. Width, " 17px " );
Writer. renderbegintag (htmltextwritertag. TD );
Imgpopup. rendercontrol (writer );
Writer. renderendtag ();
Writer. renderendtag ();
Writer. renderendtag ();
}
Add event
Code
Protected Static Readonly Object _ Click = New Object ();
Public EventEventhandler click
{
Add {events. addhandler (_ click, value );}
Remove {events. removehandler (_ click, value );}
}
This event is triggered at a certain time and handled, as shown in figure
Code
Protected Virtual Void Oninit (eventargs E)
{
Eventhandler inithandler = (Eventhandler) events [_ click];
If (Inithandler ! = Null )
{
Raiseevents ( This , e);
}< BR >}< P>
private void raiseevents ( Object sender, eventargs E)
{< br> // Body Code
}
of course, if you want to make professional controls, there are still many issues to consider. Such as support during design, comparison of client JS writing, user experience, and so on are all issues that need to be considered
the general control development process is only mentioned here.