Chapter 2 debugging technology in server control development is omitted, because many of them are used as debugging technology in development.
- Select base class: control has the most basic attributes. webcontrol has attributes such as appearance layout and style. compositecontrol implements the inamingcontainer interface and the existing control.
- Display order of controls:
- Rendercontrol
- Render
- Renderbegintag
- Rendercontents
- Renderendtag
3. Basic render display controls
Method 1:Output. addattribute (htmltextwriterattribute. href, "http://www.cnblogs.com/"); <br/> output. addattribute (htmltextwriterattribute. target, "blank"); <br/> output. addstyleattribute (htmltextwriterstyle. color, "blue"); <br/> output. addstyleattribute (htmltextwriterstyle. cursor, "hand"); <br/> output. renderbegintag (htmltextwritertag. a); <br/> output. write (this. text1); <br/> output. renderendtag (); </P> <p> output. writebreak ();
Method 2:Output. write ("<a href =" http://www.csdn.net "mce_href =" http://www.csdn.net "target = 'blank 'style =" color: Blue; cursor: hand; "mce_style =" color: blue; cursor: hand; ">"); <br/> output. write (this. text2); <br/> output. write ("</a>"); </P> <p> output. write ("<br> ");
Method 3:Htmlgenericcontrol A = new htmlgenericcontrol ("A"); <br/>. attributes. add ("href", "http://blog.csdn.net/kntao"); <br/>. attributes. add ("target", "blank"); <br/>. style. add (htmltextwriterstyle. color, "blue"); <br/>. style. add (htmltextwriterstyle. cursor, "hand"); <br/>. innertext = This. text3; <br/>. rendercontrol (output );
The third method is less efficient than the second method because it takes some time to parse it into an HTML control.
4. addattributestorender method, which is generally used with rendercontents.
Protected override void addattributestorender (htmltextwriter writer) <br/>{< br/> writer. addattribute (htmltextwriterattribute. border, "0px"); <br/> writer. addattribute (htmltextwriterattribute. cellpadding, "0px"); <br/> writer. addattribute (htmltextwriterattribute. cellspacing, "0px"); <br/> base. addattributestorender (writer); <br/>}
5. The createchildcontrols method is generally used to create a composite control.
6. The inamingcontainer interface inherits this control. Its uniqueid and clientid are added with the uniqueid and clientid of the parent control, and the Delimiter is $, _, which solves the control naming conflict.
7. Methods for implementing composite controls: createchildcontrols, childcontrolscreated attributes, ensurechildcontrols, recreatechildcontrol, control attributes, hascontrols method hasevent method, and findcontrol Method
This. namingcontainer. clientid + "_" + this. ID = This. clientid;
8. Common development skills:
- Design Mode
- Shield attributes in the basic controls: Bindable, browsable, enditbrowsable
- The page. Request. browser attribute checks the performance of the current browser.
- Set the Control ID specification, mainly used by $ and.
- Findcontrol
Private control findcontrolextend (string ID, controlcollection controls) <br/>{< br/> int I; <br/> Control find = NULL; </P> <p> for (I = 0; I <controls. count; I ++) <br/>{< br/> If (controls [I]. id = ID) <br/>{< br/> Find = controls [I]; <br/> break; <br/>}</P> <p> If (controls [I]. controls. count> 0) <br/>{< br/> Find = findcontrolextend (ID, controls [I]. controls); <br/> If (find! = NULL) <br/> break; <br/>}</P> <p> return find; </P> <p>}
- Map the server control value to the client:
Writer. addattribute ("key", this. value );
You can use document. getelementbuid (""). Key to obtain
Use the registerexpanddoattribute Method
Page. clientscript. registerexpandoattribute ("controlid", "key", this. value)
- Prohibit the derived compositecontrol control from creating child Controls
- Notes for using createchildcontrols:If (string. isnullorempty (this. validateexpression) = false & this. designMode = false) <br/>{< br/> writer. renderbegintag (htmltextwritertag. TD); <br/> This. rev. rendercontrol (writer); <br/> writer. renderendtag (); <br/>}
- Design metadata attribute defaultvalue
- Render has many base class resources.
- Conditional compilation# If net35 | net20 <br/> using system. web. UI. webcontrols. webparts; <br/> # else <br/> // If net10 is better than compiling any code <br/> # endif