Unresponsive CssClass in Asp.net Webpage

Incorporating a MasterPage into my website structure, I've added various tabs in the header section of the MasterPage using the following C# code:

<ul id="tabMenu">                 
    <li><asp:HyperLink ID="homeLink" runat="server" onclick="homeButton_Click()" 
         NavigateUrl="~/Default.aspx">Home</asp:HyperLink></li>
</ul>

Each tab follows a similar structure to the example provided. Clicking on the 'Home' tab triggers the homeButton_Click() method in the code behind, which attempts to change the CSS class to 'activeTab':

protected void Button1_Click(object sender, EventArgs e)
{
    homeLink.CssClass.Insert(0, "activeTab");
}

Despite the intended change in the CSS class, particularly altering the background-image, the current behavior is not reflecting this modification. The tab's color remains the same after clicking.

If you have any insights or suggestions on what could be causing this issue, please share.

Answer №1

Perhaps you could experiment with changing the css class in this manner:

homeLink.CssClass = "highlighted";

Answer №2

To add a CSS class to an element, you can use the following code snippet

homeLink.Attributes.Add("class", "abc");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

having trouble transferring the password field in PHP to phpMyAdmin

My HTML form collects the user's first name, last name, username, and password. I am trying to upload this data to my local phpMyAdmin, but I'm facing an issue with storing the password in the database. Below is my HTML code: <input type="te ...

Why won't my HTML DropDownList show the SelectList that I created?

I've been experimenting with ASP.NET MVC code and I am attempting to generate a DropDownList using the HTML helper in a view. However, when I create the SelectList separately and then pass the object reference into the DropDownList, it does not displa ...

Adjusting the width of speech balloon in CSS

This question might seem basic to those who are familiar with CSS (unlike me lol). I'm currently working on incorporating speech balloons into my website using this code from jsfiddle. However, I encountered an issue when the text inside the balloon i ...

Is it possible to create a responsive Material UI tab design?

How can I make the Material UI tab react component responsive? Check out the documentation for MATERIAL UI TAB here If I have multiple tab items with a search bar like shown below, how can I ensure that the input component stretches the whole width of th ...

css: text not enclosed by a span tag

I created an HTML-CSS demo with two simple span tags. I added some content to each span, and applied the same CSS code to both. Surprisingly, the content of the right span goes beyond the border, while the content of the left span stays within the border. ...

Tips for horizontally aligning a list with sublist using CSS

Is there a way to align a horizontal list with a sublist in HTML and CSS? I want the menu items (Home, News, etc.) to be on one line, with submenu items below them. HTML <body> <div class="menu"> <ul class="menu_l ...

Navigation bar links refusing to decrease in size

I am encountering an issue with the navigation bar on my website. When I reduce the size of the browser tab, the text remains the same size while the logo shrinks and eventually disappears. How can I ensure that everything scales down proportionally? Pleas ...

Place the h1 text inside of a div tag for organization

Here is an example of HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <tit ...

What is the process for transforming the search bar into an icon located at the top of a WordPress site?

For the past few weeks, I've been attempting to convert the search bar on my website (which is currently a plugin) into an icon positioned near the header. I've experimented with modifying the child theme's functions.php, the parent theme&a ...

CSS must be applied to various sections of an HTML document

For example, I have 2 CSS files. In one CSS file, I have the style: a{color: blue;} In the second file, I have: a{color: red;} I want to apply these styles to my HTML file. <div> <a>first file ...

What is the best way to target a class within a span using CSS?

I need help with hiding an icon from the mobile menu. I am unsure about how to target this specific class within the menu structure. <a class="funiter-menu-item-title" title="Nieuw">Nieuw<span class="icon fa fa-chevron-down"></span>< ...

The "add to cart" button is unresponsive

My issue is that the add to cart button on my website is not responding properly. I have implemented JavaScript on the add to cart button, where I have assigned an attribute called data-product with a value of {{product.id}}. var updateBtns = document.g ...

The left side of the form input material is obscured unless the necessary criteria are fulfilled

I am currently in the process of developing the front-end for a web application using the material library. The issue I am facing is that when a field does not meet its requirements, such as needing to enter a 'bedrijfsnaam', the border turns red ...

How can I style an image in CSS to have a set height, maximum width, and keep its aspect ratio fixed?

I am trying to place a set of images with varying heights and widths inside a div tag. My goal is to have the images maintain a fixed height, unless the width surpasses a certain limit, in which case I want the height to adjust while preserving the aspect ...

Tips for setting the tabindex on an element that has an opacity of 0

I have created a drag and drop image upload field with a hidden input element to style the upload button according to the design. However, I am concerned about accessibility and want the upload functionality to trigger when the user presses 'Enter&apo ...

What is the best way to showcase data from associated tables in View MVC4?

I am facing an issue with two tables in my database setup: Category ========= Id Name Entry ======= Title Name Username Password CategoryId. My goal is to list all entries with the corresponding Category Name at the end. For example: ID Title ...

I'm struggling to grasp the concept of the Bootstrap exercise

Being a new student can be challenging, especially when faced with a teacher who struggles to explain concepts clearly. Despite having only 4 weeks of school, I find myself unable to complete the exercises as I lack the necessary guidance. Could someone k ...

Relocate the preview division below the button in the Kartik File Input Widget

There are two input file buttons that allow users to upload an image on each button. Upon selecting an image, a preview of the image will be displayed above the button. The current layout is shown here: https://i.sstatic.net/aLAbo.png When images of diff ...

Error Encountered in ASP.NET: Access Forbidden on IIS 7.5

We recently transferred an ASP application from IIS 6.0 to a separate IIS 7.5 instance. Upon invoking a function that manipulates PDF files and sends them via email, we encountered the following error which we are uncertain how to resolve: Server Error in ...

Error: The stream was not located in SSRS 2008

We utilize SQL Server Reporting Services 2008 for constructing reports. The reports are accessed through the Webservice (ReportExecution2005.asmx) and rendered to html to be embedded in an aspx page. Our process is functioning smoothly and effectively. Ho ...