-
Website
http://john-sheehan.com/blog -
Original page
http://john-sheehan.com/blog/index.php/custom-jquery-selector-for-aspnet-webforms/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
smnbss
1 comment · 1 points
-
kevinpang
4 comments · 1 points
-
robconery
2 comments · 4 points
-
Craigslist Proxy
2 comments · -1 points
-
jeromepineau
2 comments · 1 points
-
-
Popular Threads
-
What REST APIs do you consume in your apps?
3 weeks ago · 5 comments
-
What REST APIs do you consume in your apps?
I do agree though, there are a few situations where something like "TextBox1" might happen more than once, such as multiple user controls on one page.
This is a brilliant solution John, thanks! I can't wait to try it.
I'd be fine with INamingContainer if it was limited to repeaters and such. It's master pages and user controls that cause the most problems for me.
FWIW, some time ago I updated the component you reference above and have an option to auto generate ALL clientIds on the object. As you mention the downside there is that it sends all those ids to the client when the page is loaded but you do end up with a single object with properties. (serverVars.txtNameId for example) without having to modify server code specifically to add controls. I've used this quite a bit and it works and is worth the overhead on all but really huge forms with tons of controls.
Ultimately though I've come to prefer marking up controls with pseudo classes rather than IDs. That makes it much easier:
$(".txtName").blah()
Still an extra step but an easy and also very explicit one.
What happens when you have two user controls on a page, each with a textbox1? These will be client-ized by msft as something like ctl01_textbox1 and ctl02_textbox1. Which textbox1 will your code select?
You could tell developers on large projects to communicate with one another and make sure their user controls absolutely never have nested controls with overlapping names, but ...
(BTW - great blog!)
Wish i had more time to actually offer a suggestion too, i dont think you need to extend jQuery to do what you want :¬)
Track back from http://webdevvote.com/Tips_And_Tricks/Custom_jQ...
I will continue to look into the situation myself and let you know if I find anything.
Thanks.
Instead of using:
jQuery.extend(
jQuery.expr[":"],
{
asp: "jQuery(a).attr('id').endsWith(m[3]);"
}
);
Use this instead:
jQuery.extend(
jQuery.expr[":"].asp = function(a,i,m) {
return jQuery(a).attr('id').endsWith(m[3]);
}
);
Hope this helps out
include this in any update I post.
jQuery.expr[":"].asp = function(a, i, m) {
return jQuery(a).attr('id') && jQuery(a).attr('id').endsWith(m[3]);
};
May perform slightly better if it is formed like this:
jQuery.expr[":"].asp = function(a, i, m) {
return (id = jQuery(a).attr('id')) && id.endsWith(m[3]);
};
Either way, it works fine in Internet Explorer now.
{
return element = $(type + "[id$=" + endPart + "]");
}
seemed to do the trick for me,
also using _ as leading in the endpart to avoid mismacthes.
http://jquery-howto.blogspot.com/2009/06/jquery...