Webcontrol development 3: Add attributes to all controls

Source: Internet
Author: User

The vs2003 designer has an interesting feature: During winform design, the control has no tooltip. To add a toolbox, You need to drag a special tooptip control from the toolbox, at this time, a tooltip attribute will be added to all controls on the screen, which looks cool.

It is easy to make such a control:
[Provideproperty ("XXX", typeof (system. Web. UI. Control)]
The attribute to be dynamically added here is XXXX, and the target is all control controls.
Add several attributes before the control class and there will be several dynamic attributes.

Public   Class Cultureselector: dropdownlist, iextenderprovider
{
Public   Bool Canextend ( Object Extendee)
{
ReturnExtendee! = This &&ExtendeeIsWebcontrol;
}
}

The iextenderprovider interface must be declared on the control class. Perform detailed filtering in the canextend method. For example, you only want to add dynamic attributes to textbox.

[Description ( " Allowed attributes " )]
[Category ( " Culture " )]
Public   String [] Getxxx (Control)
{
}

Public   Void Setxxxx (Control, String [] Value)
{
}

The dynamic attribute operation will call the aboveCode. Note:
1. The control parameter must be consistent with the preceding statement.
2. getxxx/setxxxx must be consistent with the preceding attribute declaration. If it is missing, it will become read-only.
3. the return value of getxxx must be of the same type as that of setxxx. Type is not limited.
4. Add [category] [description] and so on to getxxx. The usage is consistent with the actual attribute.

Add the above Code to an existing control. This control dynamically adds attributes to other controls at runtime.

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.