By default, there is a class class1, but the header does not reference webcontrols. You must add using system. Web. UI. webcontrols;
Inherit the default class1 from webcontrol
In this way, you can write the followingCode:
Protected override void render (system. Web. UI. htmltextwriter writer)
{
Writer. writeline ("Hello World ");
}
Compile and generate
Switch to Web ApplicationProgram, Add reference, project, select the previous project
Here, I have never been able to make it appear in the toolbox (but sometimes, the cause is unknown. If we add an ASP. NET Server Control and webcustomcontrol, a column and an icon will be automatically displayed)
Edit default. aspx
Enter the following code in the header:
<% @ Register Assembly = "classlibrary1" namespace = "classlibrary1" tagprefix = "PC3" %>
Then, enter <: in HTML to intelligently prompt the corresponding content.
The complete input is: <MAID: class1 id = "class11" runat = "server"/>
Knowledge point:
<% @ Register Assembly = "classlibrary1" namespace = "classlibrary1" tagprefix = "PC3" %>:
Register the user control and create an alias.
Tagprefix is the alias of The namespace. If it is changed to other content, it must be reflected in HTML and cannot be empty.
Namespace is the namespace
Assembly is the Assembly, that is, the compiled DLL file name.
Don't be confused next time.
<% @ Register %> valid only for the current page. If valid for the entire project, register it in system. web of Web. config.
<Pages>
<Controls>
<Add Assembly = "classlibrary1" namespace = "classlibrary1" tagprefix = "CC2"/>
</Controls>
</Pages>
If different aliases are also registered on the page, both aliases can be used as follows:
<PC3: class1 id = "class11" runat = "server"/>
<CC2: class1 id = "class12" runat = "server"/>
However, the alias prompts are not so sensitive. It will only take a while.
Page is indirectly inherited from the control class. The default logic of the control rendercontrol () method is to determine the control. if the visible attribute is true, the render () method is called. In addition to generating its own content, the render () method also calls the renderchildren () method to trigger all child controls, sub-control and rendercontrol ()-> render ()-> renderchildren ()
I add the following control to default. aspx:
<PC3: class1 id = "class11" runat = "server" visible = "false"/>
The running result is missing.
Then, change the override content of the control from render to rendercontrol. The result is actually visible = "false" and the effect will not be available.