0

I have a file in my project called StyleSheet.css.

Here, I have the classes for each element on my web form.

For example:

.selectEnvironment
{
    background-color: #FF0000;
}

Then I go to my control on my web form (a drop down list) and I add the CSS class to it:

   <div>
    <asp:DropDownList ID="ddlEnvironment" runat="server" AutoPostBack="True" 
    OnSelectedIndexChanged="ddlEnvironment_SelectedIndexChanged" CssClass="selectEnvironment">
            <asp:ListItem>Select Environment</asp:ListItem>
            <asp:ListItem>Development</asp:ListItem>
            <asp:ListItem>Staging</asp:ListItem>
            <asp:ListItem>Production</asp:ListItem>
        </asp:DropDownList>
    </div>

This is not working. The background color of this is not changing to red.

What am I doing wrong? I'm completely new to front end web development.

3
  • 2
    Drag style sheet from Solution Explorer into you page, or master page header, in design view ;-) Commented Sep 24, 2012 at 17:28
  • ohhh this sounds FABULOUS. trying now :) Commented Sep 24, 2012 at 17:29
  • Is the class name missing from the element or are the styles themselves missing? Inspect the element in question in your browser or view the source. Commented Sep 24, 2012 at 17:32

3 Answers 3

3

You must register your style

    <head runat="server">

      <style type="text/css">
      ...
      </style>
    </head>

You can also use this line

<link href="MyStyles.css" rel="stylesheet" type="text/css" />

You can also register in your code Behind

protected override void OnInit( EventArgs e )
{
    this.Header.InnerHtml += "<link type=\"text/css\" rel=\"Stylesheet\" href=\"styleSheet.css\" />";
    base.OnInit(e);
}
Sign up to request clarification or add additional context in comments.

3 Comments

the code is not on the web page, though. it's on a separate css file in my asp .net project
How do you know where his style sheet is located?
it's just sample IrishChieftain of registering, because the first problem is missing of regustering
2
  1. Add your style to the head portion of the MASTER PAGE. Or link the CSS.

  2. Then add the CSSCLASS to the dropdown menu.

  3. Run and see the magic. It will work.

Check below. enter image description here

LET ME KNOW IF THAT HELPS.

Regards,

Pradie

1 Comment

Don't encourage inline CSS ;-)
1

Drag style sheet from Solution Explorer into your page, or master page header, in design view. This is the easiest way to make sure that the style sheet path is correct ;-)

1 Comment

thanks irish guy! since you were the first to answer with the easiest solution, u get the green!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.