Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Does anyone know if there is an attribute I can add to a property in a code-behind file for an ASP.NET User Control to make it mandatory that the value is specified when the control is used in a page? I have seen the '[Required]' attribute somewhere but the intellisense doesn't seem happy about me using it in a .ascx file.

On a more general note, is there a good list of attributes anywhere? It all seems a bit like a black art to me, finding what attributes can be added to code where and when.

Any help would be very much appreciated.


Kind wishes, Patrick
Posted

If I understood correctly:

Why you need some attribute like required. As suggested you can use .Net inbuild requiredfield validator or You can also make validation on your server side setter of your property. If you find invalid then throw exception or show some message.

If I understood your question like:
You want any intellicense or some help while registering the user control on page it should say required properties to your developer?

Then, I would suggest to have some prepopulatd properties in your usercontrol. Say the moment someone will drag and drop your user control it should pre-populate your properties with some pre-defined values. like
HTML
<uc:mycontrol requiredproperty1="someValue" requiredproperty2="someValue1" xmlns:uc="#unknown"></uc:mycontrol>
In this way atleast develepor can see what are the properties required and can change the value according to their requirement.

Hope it helped.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900