ASP. NET control development learning notes-7th back from webcontrol

Source: Internet
Author: User

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.

Related Article

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.