CustomValidator doesn't like CssClass
-
I have a CustomValidator control in an app and for some reason it seems to ignore the CssClass property. I've tried setting this in design-mode as well as programmaticaly at runtime and it still appears without the styling. I have at least one RequiredFieldValidator that has its CssClass set to the same value and it does recognize the styling. Has anyone else had a problem with this and/or found a workaround?
-
I have a CustomValidator control in an app and for some reason it seems to ignore the CssClass property. I've tried setting this in design-mode as well as programmaticaly at runtime and it still appears without the styling. I have at least one RequiredFieldValidator that has its CssClass set to the same value and it does recognize the styling. Has anyone else had a problem with this and/or found a workaround?
I believe the "CssClass" property gets change to a "class" attribute in the generated HTML code. Thus, "CssClass='someclass'" changes to "class='someclass'". Also, you will need to have a stylesheet or (embedded stylesheet) that assigns some style such as ".someclass { color: gold; }".
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I believe the "CssClass" property gets change to a "class" attribute in the generated HTML code. Thus, "CssClass='someclass'" changes to "class='someclass'". Also, you will need to have a stylesheet or (embedded stylesheet) that assigns some style such as ".someclass { color: gold; }".
"We make a living by what we get, we make a life by what we give." --Winston Churchill
If you re-read my original question I mentioned that "I have at least one RequiredFieldValidator that has its CssClass set to the same value and it does recognize the styling.". I do have a stylesheet reference with a valid class, and as I said, other validation controls do recognize the CssClass, however, the CustomValidator does not. It seems that someone else must have experiences this.
-
If you re-read my original question I mentioned that "I have at least one RequiredFieldValidator that has its CssClass set to the same value and it does recognize the styling.". I do have a stylesheet reference with a valid class, and as I said, other validation controls do recognize the CssClass, however, the CustomValidator does not. It seems that someone else must have experiences this.
Since you weren't very specific about the value of the CssClass, I wanted to make sure you were using an appropriate value. However, I am sorry that I misread your last statement. Nevertheless, the value you gave the CssClass property must be associated with a style whether it is embedded or external. Your problem is with CSS. A possible problem could be that your "class" style is being overruled by a more local "style". For instance, if your CustomValidator sets its style attribute to "color: red;" and your class style sets its style to "color: green;", the browser will only display red text. Also, since the validators become span elements in HTML, you can only apply styles that affect inline elements unless you apply a "display: block;" style.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
Since you weren't very specific about the value of the CssClass, I wanted to make sure you were using an appropriate value. However, I am sorry that I misread your last statement. Nevertheless, the value you gave the CssClass property must be associated with a style whether it is embedded or external. Your problem is with CSS. A possible problem could be that your "class" style is being overruled by a more local "style". For instance, if your CustomValidator sets its style attribute to "color: red;" and your class style sets its style to "color: green;", the browser will only display red text. Also, since the validators become span elements in HTML, you can only apply styles that affect inline elements unless you apply a "display: block;" style.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
I guess I haven't been specific enough. The CSS is correct and the CssClass works in another validator control (required text) on the same form within the same
tag. There is no local CSS. All other standard validation controls recognize the CssClass properly. The CustomValidator is the only one that I've found that doesn't recognize the CssClass. Since this is a fairly glaring error I thought others might have come across this.
-
I guess I haven't been specific enough. The CSS is correct and the CssClass works in another validator control (required text) on the same form within the same
tag. There is no local CSS. All other standard validation controls recognize the CssClass properly. The CustomValidator is the only one that I've found that doesn't recognize the CssClass. Since this is a fairly glaring error I thought others might have come across this.
I actually created a CustomValidator with the CssClass property set to somevalue (I am using ASP.NET 2005) and ran the web application and it created the class attribute set to that value.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I guess I haven't been specific enough. The CSS is correct and the CssClass works in another validator control (required text) on the same form within the same
tag. There is no local CSS. All other standard validation controls recognize the CssClass properly. The CustomValidator is the only one that I've found that doesn't recognize the CssClass. Since this is a fairly glaring error I thought others might have come across this.
Okay, I think I have something that might work for you. Each control (I believe) has an Attributes collection that you can programically add HTML attributes to elements. You can do this with the CustomValidator:
CustomValidator1.Attributes.Add("class", "somevalue");
I am not sure this is persisted via each post. So you may have to run this code on each postback. Also, communicating via forum posts is difficult. If you don't give enough information (too much information is bad too) and I don't know your skill level, I get too general and don't answer your question properly.
"We make a living by what we get, we make a life by what we give." --Winston Churchill