tags:

views:

105

answers:

3

I'm using ASP.NET, not the newest one with that clientIdMode stuff. So, the control ids are generated and funky.

There are lots of ways of passing ids around, but lately I've been assigning a 'fake' css class to the control I'm interested in. Then in a js file I use jQuery to find the control.

Is this bad practice? It seems a lot like the ajaxControlToolkit's behaviorId to me... Is the behaviorId bad practice as well?

A: 

CSS classes are good. ASP.net classes are bad.

What I do is prepend js_ to any of my Javascript only CSS classes so I don't get confused later.

David Murdoch
+7  A: 

It's a great way to do things; I've done this plenty. The auto-generated IDs suck, although if you leave the runat="server" off, you can use those too. (I know it's not always an option, but for when it is an option, you can do so).

jvenema
This is a perfectly valid way to do things +1.
Diodeus
The auto-generated IDs suck! +1
Sepehr Lajevardi
What about this? http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx#tip8
internet man
@user, that's fine if you have ids to work with, and if performance is a problem. Generally speaking, it's not worth worrying about, and if it becomes an issue, you can, as I mentioned, leave off the runat="server" tags on some elements.
jvenema
+2  A: 

CSS classes are used to describe an element. Using a class to describe an element so that you can ientify it later is exactly what it was designed for. For this reason I would argue that it is the right thing to do.

Pheter