17 [
18 ProvideProperty("ValidationEnabled", typeof(Control)), // Names the Property to show on other controls in the designer
19 Designer(typeof(ExtenderControlDesigner<ValidationProperties>))
20 ]
21 public class ValidationProvider : ExtenderControl<ValidationProperties>
22 {
23 /// <summary>
24 /// Defines the controls which can be extended.
25 /// </summary>
26 /// <remarks>
27 /// In general, the Page, the Form, and buttons cannot be extended.
28 /// </remarks>
29 public override Boolean CanExtend(Object target)
30 {
31 if (target is Control && !(target is ValidationProvider))
32 {
33 return true;
34 }
35 return false;
36 }
37
38 /// <summary>
39 /// gets the property value for the given control
40 /// </summary>
41 public bool GetValidationEnabled(Control control)
42 {
43 return EnsureControlItem(control).ValidationEnabled;
44 }
45
46 /// <summary>
47 /// sets the property value for the given control
48 /// </summary>
49 public void SetValidationEnabled(Control control, bool validationEnabled)
50 {
51 EnsureControlItem(control).ValidationEnabled = validationEnabled;
52 NotifyDesignerOfChange();
53 }
54
55 private ValidationProperties EnsureControlItem(Control control)
56 {
57 if (control == null)
58 {
59 throw new ArgumentNullException("control");
60 }
61 ValidationProperties item;
62
63 if (this.TargetProperties.Contains(control.ID))
64 item = this.TargetProperties[control.ID];
65 else
66 {
67 item = new ValidationProperties();
68 item.ControlId = control.ID;
69 this.TargetProperties.Add(item);
70 }
71 return item;
72 }
73 }
This looks a lot like the amount of code needed to make an IExtenderProvider in Windows Forms.
Download the full source here (you have to add a webproject yourself)
I have to add a disclaimer for the use of this source because this control is not being tested thoroughly or even used till now, it can contain serious bugs!
I didn't even added XML documentation and such. (shame on me) .
The source contains a solution with 2 projects:
Naber.Web.UI Contains the base classes to use when making an IExtenderProvider
Naber.Web.UI.Controls An example ASP.NET Provider using the Generic baseclasses
Let me know what you think about this.
