Css – Can we declaratively set the Style property of a web control

asp.netcsswebforms

I’ve noticed that on aspx page IntelliSense doesn’t display the Style property of a web control, even thought the control does have a Style property. Does that mean we shouldn’t declaratively set the Style property:

<asp:TextBox ID="UserName" Style="color:Green; padding:0px; margin:0px;" runat="server"></asp:TextBox>

Best Answer

If you have to set these styles in the same file as your html then it's much better to use an embedded style that targets the ID of your control. The best solution, however, is to reference an external stylesheet (css) that contains your styles.

For example:

<style type="text/css">
  #UserName {color:Green; padding:0px; margin:0px;}
</style>