How to create an extension control of ajaxcontroltoolkit

Source: Internet
Author: User

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:

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.