An overview of Web control improvements for 2.0

Source: Internet
Author: User
Tags continue html tags implement new features visual studio|web| Control first, the introduction

So far, you've probably learned a lot about the 2.0 new features-master pages, themes, providers, and so on ... All of this is quite exciting, but have you learned any significant changes in the development of custom Web controls? That's what I want to discuss in this article. If you are already engaged in control development, then I think the new features in 2.0 described in this article will be applied immediately to your control development.

The first thing you should be aware of is that all Web controls you have previously developed with 1.1 (or 1.0) will continue to operate well under version 2.0-Microsoft has not corrupted your existing code. In this article, I'll introduce you to all the relevant content, including many new exciting technologies, all of which you can add to existing controls or use in a new control environment.

Author note This article assumes that you already have a basic understanding of custom Web control development. In this article, I take an enhanced version of the Emailcontact control as an example to make a comprehensive discussion of the Web control improvement techniques in 2.0.

   second, improve

Table 1 describes most of the significant improvements that 2.0 has made in customizing Web control development. In this series of articles, I'll take a discussion of these features.

Table 2.0 Web controls improve functionality.

Improved Describe
The new base class 2.0 also introduces some new base classes for you to derive your own controls. Later, I would highlight a control-compositecontrol.
ControlState This is the "Diqin" of the viewstate we are familiar with. There is no longer a need for a dedicated approach to state management in ControlState, and on the other hand, when a control user closes a state management mechanism on a site (or page), it helps you avoid errors.
Sensitive label This is a new feature that makes Windows control developers quite exciting! In this article, I'll show you how to add this functionality to your own custom controls.
Template design-time editing In version 1.1, it is quite difficult to add design-time editing capabilities to a control template. Fortunately, 2.0 makes it fairly easy to add this feature. I'll discuss this in the last installment of this series.
Automatic Formatting It's also a huge improvement! You can select an established format from a list of predefined formats when you use the DataGrid control. 2.0 makes it easy to add this functionality to your custom controls.
Web Resources This is an improvement I like very much because I always develop some of the controls associated with images. In 2.0, you can now publish a control's DLL without having to think about anything else. In other words, you can now embed images and other resources into the control's DLL file.

   Iii. Enhanced Emailcontact Web Controls

The custom Emailcontact Web controls in this article (refer to Figure 1) allow you to add a "contact us" form to your site that has full e-mail capabilities. In this article, I will use this feature to enhance this control.

Figure 1. emailcontact Control in default state

   四、一个 the new base class

Previously, developers derived their visual Web controls from the WebControl class. The reason I use visualization here is because, typically, controls that do not generate anything in the browser are derived from the control class. This has not changed-you should continue to use the control class to derive any such non-visual controls-they perform invisible functions or generate any other content in the browser other than the visual HTML content. Also, when you are developing a Visual Web control, you should continue to use the WebControl class. However, most of the composite controls that we develop are designed to take advantage of the functionality of existing controls. In this case, you should always derive from the WebControl class, but you should also remember some other details-otherwise, it could lead to many problems.

The composite control must implement the INamingContainer interface, and it needs to be included in your control class. This interface ensures that you have unique tag names in all HTML tags in your control and the entire control hierarchy that it can generate. This is quite critical when you have multiple composite controls of the same type on a single page. In such cases, you need to make sure that any generated child element has a unique name. Forgetting to implement this interface can lead to a variety of problems.

Before 2.0, the composite control developer also needed to remember to invoke EnsureChildControls in the Render method of a control. In my previous article, I have explained how to overload the Render method and call this method before calling the render method of the base class. It is necessary to make the control correctly build at the Visual Studio design time, otherwise it can cause a lot of inconvenience.

The above two steps are so common in composite control development that many developers tend to build a base class that includes both of these details, and then derive all of their new composite controls from the base class. As a substitute, 2.0 provided (or, more precisely, "name") CompositeControl. By using this class to build your composite control, you don't have to remember to implement INamingContainer or execute a ensurechildcontrols call from the Render method.

In addition, there are some other new base classes, such as controls for data binding, and so on, no longer repeat.

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: 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.