Unable to apply custom .css styles to nested ASP.NET Table Cell Controls

I am facing a problem where I am unable to apply a .css class to my specific asp controls within a table -> tablerow -> tablecell.

However, I can directly add 'style' using reflection (not 'class').

For example:

In .aspx:

 <asp:Table ID="_cellGrid" runat="server" CssClass="datagrid" Width="100%"></asp:Table>

In .cs:

TableRow dataTableRow = new TableRow() {  };
_cellGrid.Rows.Add(dataTableRow);

TableCell dataRowCell = new TableCell() {  };
dataTableRow.Cells.Add(dataRowCell);

Label label = new Label() { Text = "TEST" };
label.Attributes.Add("class", "custom");//THIS DOESN'T WORK
label.Attributes.Add("style", "background-color: Red; font-size:2.1em;");//THIS WORKS

dataRowCell.Controls.Add(label);

In .css:

.custom {    
background-color: Red;
font-size:2.1em;    
}

The .css file is correctly linked in my master page and I use it elsewhere on the same control (outside of the Table).

I do not want to use inline style .css throughout the table, and I require different styles for individual custom controls within table cells. Therefore, capturing the "table_row" css associated with asp:Table or other built-in elements is not possible (let me know if clarification is needed, I have a good example on this too).

If you can assist, please do so. It appears to be a simple task, yet here we are.

Answer №1

Apologies for the inconvenience, it turns out there was a cache issue causing this problem. I typically use Chrome incognito mode for debugging, so I wasn't expecting to come across this particular issue.

Thank you for your understanding.

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

A custom class that uses toggleClass() does not trigger an alert upon a click event

I am encountering an issue with the toggleClass() function in jQuery that I haven't seen addressed before. Despite successfully toggling the class of one button when clicked, I am unable to trigger a click event on the newly toggled class. Here is th ...

Encountering difficulties constructing a .NET project using Nant

Issue Detected Error code MSB3091: The task is failing because it cannot locate "sgen.exe" or the .NET Framework SDK v2.0 is missing. It seems that the task is expecting to find "sgen.exe" in the "bin" folder within the location specified by the SDK ...

Exemplary CSS Text Alignment When Vertical Align is Exceptional

I'm currently working on a menu where some text needs to be aligned vertically with the property vertical-align:super. However, I am facing an issue where this particular item with "super" text is not aligning properly with the other items. Below is ...

Retrieve text from an element using jQuery when triggering "mouseenter" on a different element

Is there a way to retrieve the text from an element while simultaneously triggering a 'hover' action on another element? Here is an illustration: I am trying to gather all available colors, but the color names are only visible upon hovering ove ...

The performance of ajaxtoolkit - OnChanged event appears to be malfunctioning

I recently downloaded the ajaxtoolkit and attempted to use the Rating object in a basic way. However, I noticed that the OnChanged event is not triggering. Can anyone help me understand what I may have done incorrectly? Below is the code snippet: < ...

What is the correct way to properly define the height of a page containing an angular-split area?

I am currently working on a page that utilizes angular-split. Here is a snippet of the code: <div class="height-max"> <app-nav-menu></app-nav-menu> <as-split direction="horizontal"> <as-split-area> <route ...

Guide to interacting with models in ASP.NET MVC (updating in the post controller)

As a newcomer to MVC, I am finding the concept of models confusing. It seems that only one model can be used per action. public class TestModel { public string foo1 { get; set; } public string foo2 { get; set; } public string foo3 { get; set; ...

Delay the jQuery event handler for a few milliseconds before triggering

I'm currently working on a navigation menu, but I've encountered some bugs and I'm struggling to fine-tune it completely. Here are the issues I'm facing, and any help or solutions would be greatly appreciated. The menu items (About ...

Issues with Bootstrap sidebar and footer functionality

I need to implement a consistent footer on multiple web pages created with jQuery and bootstrap 3. Following the example provided by Bootstrap, I have written the script below to add the footer: // Default $( document ).ready(function() { $(' ...

Spin only the outline with CSS

I have a unique idea for my webpage - three spinning circles surrounding text, while the text itself remains stationary. My challenge is to achieve this effect using only CSS, specifically by utilizing the .spinner-border class from Bootstrap. I cannot ma ...

Consecutive Wins: A C# Program Gaming Experience

Check out this game board to see its current layout (it will soon be expanded to a 7x6 grid). I aim to identify a winner in the game by detecting when two colors are aligned horizontally or vertically, inspired by the concept of "connect four". Additional ...

Exploring the World of Print CSS, Embracing Bootstrap, and Master

In continuation of my previous query, I am facing an issue with setting up a filemaker foreach loop to display a group of images along with their names and IDs, accompanied by checkboxes. Upon checking the relevant checkboxes, the corresponding images are ...

Base type invoked in a generic function

In my current situation, the code looks like this: public class Foo{} public interface IBar<in TEx> where TEx : Exception { Foo Build(TEx ex); } public class FooFactory{ public Foo Create<TEx>(TEx ex) where TEx : Exception{ ...

Is it possible for a gradient between accessible colors to also be accessible?

Ensuring accessibility on websites is a top priority for me, with our goal being at least AA standard. We utilize tools like and to test the contrast between background colors and black or white text. For example, let's consider white (#fff) text a ...

Chaos in the IE8 drop-down menu situation

I'm having trouble with my code for a menu with drop-downs in ie8. It works fine in all other browsers but there seems to be an issue with the positioning of the main menu and submenus. Any thoughts on what might be causing this? <ul id="nav" clas ...

Background and border presentation issues arising from CSS conflict

While working on a webpage, I encountered a design conflict within a div that contains a group of other div elements. The current appearance can be seen at , and the desired look is shown in the image here: enter image description here ...

CSS Dynamix - Include the parameter ?value to resolve caching issues

I came across a discussion on the issue of Dynamic CSS caching problem where it was suggested to append ?value to the end of the css file name for better caching. I am currently using themes and the css files are loaded automatically. Is it possible to use ...

Using Common Table Expression in Entity Framework

I'm facing a challenge in Sql Server where I have a query that needs to be translated into EntityFramework. How can I write EntityFramwork code that will produce the same result as this SQL query? WITH cte AS ( SELECT * FR ...

tips for arranging the body of a card deck

I have a card-deck setup that looks like this https://i.sstatic.net/vuzlX.png I am trying to arrange these boxes in such a way that the total width of the box equals the sum of the Amazon Cost width and the BOXI+ width: https://i.sstatic.net/3uNbe.png He ...

Switch up the CSS variable within an embedded iframe

I'm in a predicament with a specific issue. I am currently utilizing Angular to incorporate an Iframe. Let's imagine the angular app as A and the Iframe as B. B is being loaded within A. Within B, I have utilized CSS variables to define colors. I ...