Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 703
ACP Avatar asked Nov 19 '09 13:11

ACP


People also ask

What is HTML generic control?

Or the HtmlGenericControl is used to control other HTML elements not specified by a specific HTML server control, like <body>, <div>, <span>, <font>, <p>, <ul>, <li> and so on. Suppose you create a menu with submenu items in HTML. In this situation the inner content of the HTML control tags will not changed.

Can we use CSS in asp net?

ASP.NET Web pages function as HTML pages at run time. You can therefore use cascading style sheets (CSS) to set the appearance of any elements on the page other than Web server controls.

What is UL in asp net?

In HTML, there are the following types of lists: Unordered Lists (<ul>) - The list items are marked with bullets. Ordered Lists (<ol>) - The list items are marked with numbers or letters.

Does ASP Net use HTML and CSS?

ASP.NET is a free web framework for building great websites and web applications using HTML, CSS, and JavaScript.


1 Answers

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

like image 182
Muhammad Akhtar Avatar answered Sep 21 '22 17:09

Muhammad Akhtar