7th back from webcontrol
Finally, I saw professional ASP. NET 2.0 Server Control and component development the third chapter of this book, the second chapter I did not talk about, is the user control (ascx control), has been omitted, now first focus on custom control. The third chapter of this book is about custom styles. It is very powerful to analyze some of the webcontrol source code! I am also very careful. I suggest you buy this book. Since reading English is not as easy as reading Chinese, I only read it for the first time. It seems that I am not familiar with it. It is much clearer to read it for the second time. Let's start with webcontrol.
What is webcontrol? What is the function? It exists in system. Web. UI. webcontrols, which is named null, and inherits from control. Like the control class, it is also a basic class for writing controls. What is the difference between the two? We use the most intuitive way to show the differences between the two. Create a file "fromcontrol. cs" and enter the following code:
Example 7-1Code 1:Fromcontrol. CSCode
Using system. Web. UI;
[Assembly: tagprefix ("mycontrol", "CG")]
Namespace mycontrol
{
Public class fromcontrol: Control
{
Protected override void render (htmltextwriter writer)
{
Writer. writeline ("I inherit from control ");
}
}
}
Create a new file "fromwebcontrol. cs" and enter the following code:
Example 7-1Code 2: Fromwebcontrol. CSCode
Using system;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
[Assembly: tagprefix ("mycontrol", "CG")]
Namespace mycontrol
{
Public class fromwebcontrol: webcontrol
{
Protected override void render (htmltextwriter writer)
{
Writer. writeline ("I inherited from webcontrol ");
}
}
}
Control and webcontrol are inherited as two controls. Create a compile. BAT file and enter the following code:
Example 7-1GenerationCode 3: Compile. Bat code
CSC/T: Library/out: H: \ ASP \ bin \ fromcontrol. dll H: \ ASP \ fromcontrol. CS
CSC/T: Library/out: H: \ ASP \ bin \ fromwebcontrol. dll H: \ ASP \ fromwebcontrol. CS
Pause
Remember, do not copy my path, depending on your actual situation. Double-click compile. BAT to generate two DLL files in the bin folder. Create an ASP. NET web application in Visual Studio. And add these two controls to the toolbar (we have discussed how to get the control into vs before, and I will not comment on it here ). Well, place the two controls in the design form, select the two controls respectively, and observe the Properties window, as shown in 7-1:
Let's look at the differences in attributes. You should have a visual understanding of the differences between them! Of course, the difference is far more than that. If you are busy now, let's talk about it. I will talk about it tomorrow.