Resolution of any property / attribute on server / usercontrol

I noticed that on most, if not all, standard web controls in the System.Web.UI.WebControls namespace, you can add any properties you want to them without page crashes.

Take an asp: Button control for an example.

This code is absolutely correct:

<form runat="server">
    <asp:Button runat="server" Text="Test button" crapAttribute="crapValue" />
</form>

Now I have a custom server control that crashes if I add arbitrary attributes to it. It accepts only attributes that have the corresponding public property.

The error I get looks something like this: "The control does not have a public property named" crapAttribute "."

I would like my user controls to be able to accept any attributes without crashing. What do I need to do for this?

I looked at the standard controls in Reflector, and they have all kinds of attributes and more, but I did not see anything that immediately caught my eye.

My user controls inherit from WebControl for what it costs.

+5
source share
2 answers

You do not need to do anything, in particular, to add attribute attributes. Things originating from WebControl typically scoop up these attributes and upload them to the collection of attributes.

, . Attributes Render, .

, ?

+4

-

myCustomControl.Attributes.Add("customproperty", "value");

.

, .

0

All Articles