I’m working with ASP.Net and trying to style an ImageButton. I tried to do this via CSS only to discover that for some reason, .Net writes out an inline style setting the border width to 0 automatically. This overrides the border width from CSS, so I have to set it manually in the codebehind.
My question is, should I do all the styling in the codebehind to keep it all in one place, or only do the border width there and do the rest in a style sheet?
For clarification, I mean all the styling for that object not for the whole site.
5
It seems like doing all of your styling in code-behind because of one particular bug issue is like throwing out the baby with the bathwater.
I say you should fix the one issue in code-behind, with a comment explaining why it’s done that way, and perhaps a comment in the CSS file explaining why it’s not done there. Then go on with life. 🙂
3
The best way may be to try and remove the inline style with JavaScript, though I’m not 100% sure that would work. The biggest problem with doing all the styling in the code behind is that you must redeploy the actual code for a style change, which may or may not be an issue, if you put all the other styling in the style sheet it can be changed only by replacing that file. When you are working with CSS though getting it to work in any way is a victory, your options all suck in some way, splitting up styling information or working with CSS in the codebehind or hacking it together with JavaScript.
Does it need to be an imagebutton? Personally I’d use the more accessible real button and then use CSS to put the background image in.