Before reading this article, you must complete the installationMicrosoft ASP. NET Ajax V1.0 Beta(For details, seeEmbrace change--SlaveAtlasToASP. NET Ajax(1): Download and install Overview). After the installation is complete,Visual StudioCreatingWeb SiteThere will be an additional template:ASP. NET Ajax enabled web site. The subsequent content will be based on the newly createdASP. NET Ajax enabled web site.
Summary
InASP. NET AjaxExtender control is equally important. If updatepanel only introduces the core concepts and basic features of Ajax-local update and asynchronous delivery. net, then the extended control takes a new step in this basic feature-adding rich client functions to the page, allowing users to see at a glance: Oh, this website is really "ajax!
This article analyzesAtlasASP. NET AjaxMediumExtendersControls.
Extended controls
ASP. net Ajax provides two built-in extended controls: dragoverlayextender and autocompleteextender. The former allows you to drag and deploy a part of the page, the latter can add the Automatic completion function for a textbox. In this way, the textbox will have a behavior similar to that in the browser address bar. After you enter a piece of text, the matching prompt option will pop up automatically. For more information about how to use the autocompleteextender of the CTP version, seeUse ASP. Net Atlas AutoComplete behavior or AutoComplete extender to implement automatic completion (upper) and ASP. Net Atlas AutoComplete behavior or AutoComplete extender to implement automatic completion (lower ).
The implementation principle of the extender control is not complex: Asp. net Ajax will put ASP.. NET page. net Ajax client behavior (behavior) Declaration, and added to the page, all other implementations are implemented by ASP.. Net Ajax client runtime processing. When the page arrives at the client, the ASP. Net Ajax framework of the client runs this behavior on the client. For more information about ASP. NET Ajax client behavior, see create a custom behavior in ASP. NET atlas.ArticleBased on the CTP version, part of the content is outdated ).
Another Microsoft Company andCommunityA free and open-source third-party control package-Asp. net Ajax Control Toolkit provides more and even all-encompassing extensifier controls, covering almost all common rich client functions, and is still growing rapidly. These controls are used exactly the same as the extensions built in ASP. NET Ajax, Making developers feel more cordial. The extended controls provided in ASP. NET Ajax Control Toolkit will be detailed in chapter 7th, 8, 9, and 10 of this volume. ASP. NET Ajax Control Toolkit also provides the infrastructure (control base class, etc.) of the extended control and project templates in Visual Studio. With these convenient facilities, we can also easily develop custom controls. For more information about the development of server extender controls, see ASP. net Atlas server extender control-basic concepts and pre-requirements, ASP development. net Atlas server extender control-write client behavior and Develop ASP. net Atlas server-side extender control-write server-side extender & dflying recent trends and Develop ASP. net Atlas server extender control-used in actual development (Note: This article is based on the CTP version, and some of the content is outdated ).
How to use the extended controls of the CTP version
Generally, we can use the extended control in the CTP version as follows:
-
- Make sure that there is a scriptmanager control on the page where you want to apply the extender control, and the value of its enablescriptcomponents attribute must be set to true (this is also the default value ). Because the extender control will generate the Atlas client behavior (behavior), and then entrust this behavior to complete the real client expansion work, the behavior operation requires the complete Atlas client framework support.
- PageSource codeAdd the declaration of the extended control after the scriptmanager control declaration. Add a tag similar to <Atlas: [extender name] extender> and assign an ID to it. Of course, there is also an essential runat = "server ". This label can be considered as the classification of all the extended controls of the same type on the Atlas page. You can also specify certain attributes of the extended device in this label, which is the same as those of the minimumprefixlength, servicemethod, and servicepath attributes of the autocompleteextender extended device.
-
- Add the extended property declaration label in the Declaration label of the extended control, that is, add the label similar to the <Atlas: [extended name] Properties> label in the <Atlas: [extended name] extended der> label. The extended target (targetcontrolid attribute, which is supported by each <Atlas: [extended device name] Properties> tag .) And its proprietary attributes (for example, the enabled attribute of <Atlas: autocompleteproperties>) can be set in this tag.
-
- For the same attributes exposed in the <Atlas: [extended device name] Properties> tag and <Atlas: [extended device name] extender> tag, you can set either of them. However, if both are set, the value in the <Atlas: [extended device name] Properties> label is used, that is, <Atlas: the setting in the [extender name] Properties> label overwrites the setting in the <Atlas: [extender name] extender> label. Select the tag <Atlas: [extended device name] Properties> and <Atlas: the setting location of the attribute in the [extender name] extender> label will help reduce the declaration part of the extender when the page contains multiple identical extended controls.CodeQuantity.
- Multiple <Atlas: [extended device name] Properties> tags can be defined under the <Atlas: [extended device name] extender> tab. In other words, to use an extended widget that has already been used on the page, you can add a new <Atlas: [extender name] extender> tag and add the corresponding <Atlas: you can also add a new <Atlas: [extended device name] Properties> tag in the original <Atlas: [extended device name] extender> tag. In general, we should try our best to use the latter method, because it can make the code concise and easy to understand. However, not all extensifier controls can be used in every case. Can an extensifier control fully support this method and add only another additional one? <Atlas: the [extender name] Properties> label method to add multiple extenders to the page depends on the control design <Atlas: whether the property exposed in the [extender name] Properties> label can fully overwrite the property exposed in the <Atlas: [extended name] extender> label.
-
- An existing ASP. Net control can be added with multiple extended controls using different <Atlas: [extended device name] extender> label declarations.
Changes in the use of extended controls from CTP to Beta
In beta, Asp. the concept of the. NET Ajax extender control is greatly simplified. The <Atlas: [extender name] extender> and <Atlas: [extender name] Properties> labels in the CTP version are removed, instead, use the <asp: [extender name] extender> label. All attributes are also set in the <asp: [extended device name] extender> label.
How to use the extended controls in Beta
Generally, we can use the extended control in beta (also applicable to the extended control in ASP. NET Ajax Control Toolkit) as follows ):
- Make sure that there is a scriptmanager control on the page where you want to apply the extender control. Because the extended control will generate ASP. net Ajax client behavior, and then delegate to this behavior to complete the real client expansion work, and the behavior operation requires a complete ASP.. Net Ajax client framework.
- In the page source code, add the declaration of the extended control after the scriptmanager control declaration. Add a tag similar to <asp: [extended device name] extender> and assign an ID to it. Of course, there is also an essential runat = "server ".
- The extended target control of the extender (specified by the targetcontrolid attribute) is indispensable. Any extended control supports this attribute. We should point it to the server-side control to be "extended", such as the autocompleteextender example above.ProgramThe property is directed to a textbox on the page.
- Set the exclusive attributes of the extended control, such as the servicepath and servicemethod attributes of autocompleteextender.
- We can add multiple extended controls for an existing ASP. NET control. These functions will be combined and applied to the target control.
Decorator pattern)
The Extender control in ASP. Net Ajax is a very typical and perfect application of the decoration mode.Design PatternAs mentioned in the book, there are several usage cases of the decoration mode:
- Add roles to a single object dynamically and transparently without affecting other objects.
- Handle unrecoverable responsibilities.
- When the subclass generation method cannot be used for expansion. One case is that there may be a large number of independent extensions. To support each combination, a large number of subclasses will be generated, resulting in explosive growth of the number of subclasses. Another scenario is that the class definition is hidden, or the class definition cannot be used to generate a subclass.
The extended controls in ASP. NET Ajax are well reflected in these three usage cases. Let's take the autocompleteextender control applied to the Textbox Control in ASP. NET as an example:
-
- Not all textbox in the application requires automatic completion. Generally, textbox that requires automatic completion accounts for a very small proportion of the entire application. If inheritance is used to implement this function, Automatic completion is not used in most textbox functions. In addition, this inheritance implementation method also needs to modify the existing code (change the <asp: textbox> label to a label similar to <asp: autocompletetextbox> ). It not only increases the difficulty of extending existing programs, but also increases the possibility of errors during the modification process.
-
- To temporarily control whether the auto-completion function is enabled in the program, you only need to simply change whether to add the autocompleteextender Control for it. If you use the Inheritance Method to dynamically create a textbox in the program, you need to select different objects (textbox or autocompletetextbox) for creation, which is troublesome; if you use the decoration mode extended control, you can always create the same Textbox Control class first, and then decide whether to create autocompleteextender based on whether to automatically complete the function. Even if the textbox does not need to be automatically completed in the running of the program, we do not need to make any changes to the textbox, as long as we remove the added autocompleteextender.
- For ASP. net Textbox Control, we can use autocompleteextender to provide automatic functions, or use ASP. the filteredtextbox extender in net Ajax Control Toolkit allows users to enter text in only one of the specified modes. In this way, if we use the inheritance method to implement these two extensions, we must maintain four types of objects in our system: Textbox, autocompletetextbox, filteredtextbox, and filteredautocompletetextbox. If we want to add a watermark to the textbox one day (that is, Asp. net Ajax Control Toolkit textboxwatermark extended functions), the textbox type to be maintained will be increased to eight! In the long run, the results of this "class explosion" will make the system very difficult to expand or maintain. If the decoration mode extender control is applied, you only need to maintain the extenders and select and add them to a textbox as needed.
Thoughts on Writing
- Structured and organized discussion
- The article must conform to the reader's reading habits (repeated many times)
- I seem to be more and more capable of writing, but the language is getting pale.
- Embracing changes is a little tiring
- (I haven't thought about it ......)
(PS: Part of this article is self-selected Atlas-Asp. net Ajax program design-Volume I: server-side ASP. NET 2.0 Ajax extensions and ASP. net Ajax control toolkit, which will be published in next January. Hope you can support it .)