remove css class in code behind
You can replace "required" with an empty string:
lblName.CssClass = lblName.CssClass.Replace("required", "");
Remove a CSS class from HTML element in the code behind file
This will remove all CSS classes from the div with ID="mydiv"
Me.mydiv.Attributes("class") = ""
How remove css class in code behind .net 2.0
You can make the same. CssClass just return string, so you can do like this
MyDivId.Attributes["class"] = MyDivId.Attributes["class"].Replace("addedClass", "");
UPDATE1
Or just more easy to use way to create extension class that will do the same:
public static class ControlExtension
{
public static void RemoveCssClass(this HtmlControl control, string cssClassName)
{
var val = control.Attributes["class"];
val = val.Replace(cssClassName, string.Empty);
control.Attributes["class"] = val;
}
}
And then use it:
MyDivId.RemoveCssClass("addedClass");
Removing CSS class from li tag in ASP.net from code behind
I've just made a sample to test your code, and found that the following part will do exactly what you want:
var newClassValue = liTest.Attributes["class"].Replace("NoDisplay", "");
liTest.Attributes["class"] = newClassValue;
Tested and Working:
if (for some reason) the above code didn't work, I would recommend another approach, which is similar to the previous, with another way to replace the class value
var newClassValue = liTest.Attributes["class"].Replace("NoDisplay", "");
liTest.Attributes.Remove("class");
liTest.Attributes.Add("class",newClassValue);
removing class from a div in c#
If you are wanting to read the class name, you will need to use the code:
string className = Test.Attributes["class"].ToString();
If you are wanting to replace a specific class you will need to use the code:
Test.Attributes.Add("class", Test.Attributes["class"].ToString().Replace("spacerDiv", ""));
Add and remove CssClass ASP.NET
Have you tried SelectedRowStyle
?
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrowstyle.aspx
change css class in code behind
try this way FeedbackLabel.Attributes.Add("Class", "feedback fail")
.
you shouldn't use .
for specifying class attribute value for element
Changing user control css class in code behind
So I solved the problem by defining the ListViews ItemDataBound event handler and assigning the css class in there. The problem previously was, that since my controls were inside updatePanels the ItemDataBound event was not firing. I had to manually call "DataBind()" inside the click method.
Inside my default.aspx
// Exposed click event, updates RecentBooks control sqlDataSource.
private void SidebarItems1_Clicked ( object sender , EventArgs e ) {
RecentBooks1.updateDataSource( SidebarItems1.FacultyId.ToString() );
SidebarItems1.DataBind();
}
Inside my user control.ascx
protected void sidebarListView_ItemDataBound ( object sender , ListViewItemEventArgs e ) {
LinkButton button = e.Item.FindControl( "NameLabel" ) as LinkButton;
if (FacultyName != null && button != null) {
if ( button.Text == FacultyName ) {
button.CssClass = "sidebarItemActive";
}
}
Can't Change CssClass From Code Behind
As suspected, the problem was that a partial postback was occurring in which only the contents of the update panel were being re-rendered.
That said, all the server side page lifecycle events were still being invoked. This is what confused me as I could debug and see the CssClass being applied but not being rendered in the html. Just the way Asp.Net update panels work I guess.
Related Topics
How to Stream Webcam Video with C#
How to Intercept All Key Events, Including Ctrl+Alt+Del and Ctrl+Tab
Invoke C# Code from JavaScript in a Document in a Webbrowser
What Is the "Volatile" Keyword Used For
Convert Byte Array to Image in Wpf
Determine the File Type Using C#
Divide Array into an Array of Subsequence Array
How to Loop Through a Date Range
Is There a C# Case Insensitive Equals Operator
How to Find All Possible Subsets of a Given Array
Webbrowser Control IE8 Compatibility Mode On/Off Switch
Handling Decimal Values in Newtonsoft.JSON
How Does Creating a Instance of Class Inside of the Class Itself Works