Last post Dec 04, 2008 10:52 AM by guybrush
Dec 02, 2008 03:37 AM|guybrush|LINK
(How) is it possible to mark a property of a derived control as "required"? I am looking for something similar to the "runat"-property of WebControls: if you do not specify it, VS shows an error message, even in source edit mode.
My control does have a property that needs to be set in ASPX markup and I would like to enforce that. I am using .NET 2.0 here in case this matters.
Dec 02, 2008 09:51 AM|volnay|LINK
i know that it is implemented in the autocompleteExtender control of the ajaxcontroltoolkit. they use an attribute in the
ServiceMethod property declaration to set it as required. So yes it is Possible.
But i am not sure how it is handled in the control creation to throw an exception
Dec 04, 2008 10:52 AM|guybrush|LINK
Thank you for the tip. It helped me find solve some of the misteries. It is implemented using a custom attribute which is checked whenever a method is called. If the property is null, an AttributeException is thrown. But this method (i forgot the name, something
like "GetScriptDescriptor()") is specific to AJAX-controls (I think).
As my control is no AJAX control (that is it does not derive from BaseControlExtender (or something similar)) there is no such method. I tried to check if the property is null in OnInit(), which does work at runtime (at least) but not during design time.
Although I read somewhere that OnInit sould be called during "creation of a new control during design time".
Now I am thinking that the focus would best be on the XSD describing the (ASPX-) markup... If I could "learn" it that my custom control *has to have attibute foo* VS would complain, I assume. The question is: (how) can I *extend* (not replace) the "default"
XSD VS uses to check ASPX-markup?
What do you think about that approach?