Microsoft's ajaxcontroltoolkit provides an easy extension method. I am also a beginner of ajaxcontroltoolkit extension. So here is an example to learn it together, if you have any suggestions or examples, please share them with us.
In fact, the extensions provided on the Microsoft Ajax official website are very detailed. In addition, there is an example. Strictly speaking, it is a bit simple. However, to sum up each extension control, you should pay attention to the following points:
1. required DLL: system. web. DLL, system. web. extensions. DLL, system. design. DLL, system. web. extensions. design. DLL. finally, ajaxcontroltoolkit is the most important DLL.
2. A Class must inherit the extendercontrolbase class.
Many basic rules and some required attributes are in the extendercontrolbase class. For example, each control requires a targerconrolid.
In addition, webresource and cliendtscriptresource are encapsulated.
As follows:CodeAs shown in:
Copy code The Code is as follows: using system. componentmodel;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using ajaxcontroltoolkit;
[Assembly: system. Web. UI. webresource ("customextenders. mycontrolbehavior. js", "text/JavaScript")]
Namespace customextenders
{
[Clientscriptresource ("customextenders. mycontrolbehavior", "customextenders. mycontrolbehavior. js")]
[Targetcontroltype (typeof (textbox)]
Public class mycontrolextender: extendercontrolbase
{
[Extendercontrolproperty]
[Defaultvalue ("")]
Public String myproperty
{
Get
{
Return getpropertyvalue ("myproperty ","");
}
Set
{
Setpropertyvalue ("myproperty", value );
}
}
}
}
3. js files used:
After completing the preceding steps, a custom control progress bar is created.
It is meaningless to say so many theories. What we need is a complex and useful example. The following is an example:
First, let's take a look at the running effect:
Based on the above theory, let's implement it step by step:
1. Reference dll:
As shown in, we have added several required DLL files in the new project. Which assets package uses CSS and images.
2. Create a derived class:
The most important thing is to encapsulate webresource and clientresource. The encapsulation code is as follows:
And then add the attributes. All attributes are added as follows:
3. Write JavaScript,
No code is posted here.
Use this control on the front-end page: