Apply CSS for an HTML generic control like <UL> and <LI> in ASP.NET

23,649

Please try this,

ull.Style.Add("background-color", "Red");

Or, I have tested this, will definitely work, please check

ull.Attributes.Add("class", "yourClass");

Edit: To test this solution I have provided you:

  1. make new blank master page and put <ul runat="server" id="ull">

  2. then add a new page and use the above master page.

  3. make findcontrol ul and put in CSS as I have mentioned in the answer.

  4. then run your page, and view source of your HTML page and you will find what you are looking for. Like

Share:
23,649
ACP
Author by

ACP

Updated on August 11, 2022

Comments

  • ACP
    ACP over 1 year

    I don't know how to apply CSS for a HTML generic control like <UL> and <LI> given runat="server" in ASP.NET. I am finding the <li> in a master page from a content page. Once I found that control I want to apply CSS.

    <ul id="mainMenu" runat="server" style="width:350px;">
        <li id="mainHome" runat="server"><a title="Home" href="#" class="home">Home</a></li>
    
        <li id="mainManage" runat="server"><a title="Manage" href="#"
                                              class="manage">Manage</a></li>
    
        <li id="mainEnquiry" runat="server"><a title="Enquiry" href="#"
                                               class="enquiry">Enquiry</a></li>
    
        <li id="mainReport" runat="server"><a title="Report" href="#"
                                              class="report">Reports</a></li>
    </ul>
    
  • ACP
    ACP over 14 years
    Hai Akthar, I use find control to find a list named "home" like this Control list = this.Master.FindControl("mainMenu").FindControl("mainHome"); now how to aplly css for the control list....