• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1711
  • Last Modified:

How do I style Asp.net controls using CSS ?

Hi,

I have a fairly descent understanding of both CSS and Asp.net, but not sure how to put them together.   For example, how can I apply CSS button styling to a ASP control button?  Thanks for any help.
0
P1ST0LPETE
Asked:
P1ST0LPETE
4 Solutions
 
Maverick_CoolCommented:
just defining class
0
 
NazoUKCommented:
ASP.NET controls are just rendered as standard html elements so any stylesheet rules you define for those elements will apply to the corresponding asp.net controls too (eg. asp labels are spans, panels are divs, gridviews come out as tables etc etc).
Additionally most controls also have a "cssclass" attribute that you can use to specify a css class for that particular control on the server tag.  eg <asp:button runat="server" ID="button1" cssclass="btnStyle" /> that kind of thing.
Something to watch out for though is that the ID attribute doesn't necessarily come out the same when rendered (if in user controls, templated controls etc) so care needs to be taken when using the #selector in your style sheet.
0
 
raja_ind82Commented:
Here is the sample code:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <style  type ="text/css" >
    input.btn{
   color:#050;
   font-family:'trebuchet ms',helvetica,sans-serif;
   font-size:small;
   font-weight:bold;
    background-color:#fed;
    }
   </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnSubmit" runat="server" cssclass="btn" Text="Submit" />
      </div>
    </form>
</body>
</html>

Thanks,
M.Raja
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
P1ST0LPETEAuthor Commented:
So the style sheet needs the "runat="server" attribute as well for it to work correctly?
0
 
NazoUKCommented:
No, the style sheet interacts with the html elements, not the server ones.
0
 
P1ST0LPETEAuthor Commented:
Thanks for the help guys.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now