Author: Dflying Chen ( http://dflying.cnblogs.com/ )
PS: Thanks to everyone's love, I have learned a lot during the two months I have settled in the blog park, made many friends, and received many opportunities. Currently I have the honor to translate an Atlas book: Foundations of Atlas: Rapid Ajax Development with ASP.NET 2.0, which is expected to be published by the People's Posts and Telecommunications Publishing House in three months. Therefore, I have been quite busy during this period, and the blog cannot be updated as frequently as it was some time ago. I hereby apologize. Of course, friends are welcome to continue discussing Atlas-related questions, and I will try my best to answer them.
In the next two months, I hope to strive for excellence in the translation of Foundations of Atlas, so there will definitely be many issues that need to be discussed with friends, such as terminology, translation style, etc. Thank you in advance here!
In the previous article (please refer to: Developing ASP.NET Atlas server-side Extender control - writing client-side Behavior), we have already written the client-side Behavior. In this article, let's wrap it up and run it as a server-side control.
First come to the ValidateUserNameProperties.cs file. This class inherits from the TargetControlPropertiesBase<Control> base class, which defines the mapping relationship between client property values and server property values. At the same time, the TargetControlPropertiesBase<Control> base class and Atlas Control Extender have already done the work of generating client-side XML Script for you. You only need to define the attributes required by your Behavior.
Five attributes, CheckResultLabelID, ServiceName, MethodName, ValidMessage and InvalidMessage, should be added. For the sake of simplicity, I only give an example of an attribute
[DefaultValue("")]
[IDReferenceProperty(typeof(WebControl))]
[RequiredProperty()]
public string CheckResultLabelID
{
get
{
return GetPropertyStringValue("CheckResultLabelID");
}
set
{
SetPropertyStringValue("CheckResultLabelID", value);
}
}
The definition of CheckResultLabelID is preceded by three attributes:
DefaultValue: Set the default value of this attribute.
IDReferenceProperty: Specifies that this property can only store the ID of a specific type of control.
RequiredProperty: Specifies that this property is required.
For several other properties, you can refer to the source files provided later.
Then take a look at the ValidateUserNameExtender.cs file. The main parts are as follows:
[Designer(typeof(ValidateUserNameDesigner))]
[ClientScriptResource("Dflying", "ValidateUserNameBehavior", "Dflying.Atlas.ControlTookit.ValidateUserName.ValidateUserNameBehavior.js")]
[RequiredScript(typeof(ValidateUserNameExtender))]
public class ValidateUserNameExtender : ExtenderControlBase<ValidateUserNameProperties, Control>
{
}
Among them, our ValidateUserNameExtender inherits from the ExtenderControlBase<ValidateUserNameProperties, Control> base class and gets some common operations. And three attributes are applied to the class:
Designer: Specify the class name of this Extender's designer (used to provide design-time support).
ClientScriptResource: Specifies the information required to generate client Atlas XML scripts. The Dflying and ValidateUserNameBehavior here must be consistent with those defined in the previous ValidateUserNameBehavior.js.
RequiredScript: Specify the script required by the client, so that Atlas will link ValidateUserNameBehavior.js to the page in the form of an axd file.
Finally, there is the ValidateUserNameDesigner.cs file, where you can add design-time support. Let your control have different display styles with different property values set in Visual Studio. To simplify here, I will not add design-time support.
At this point, our Extender has been written, and the DLL generated after a Release Build can be used directly. In the next article, I will demonstrate using this Extender in a real program.