Extending jQuery to Select ASP Controls
One thing that has always been annoying about programming JavaScript in an ASP.NET Web Forms environment is that the ID attribute of HTML controls rendered out from ASP controls is unpredictable.
<asp:TextBox runat="server" ID="txtPhoneNumber" />
renders out as something like:
<input type="text" id="ctl00_ctl00_ctl00_main_Content_txtPhoneNumber" name="ctl00$ctl00$ctl00$main$Content$txtPhoneNumber" />
I did a write up over on the LANIT development blog about a solution to this problem using jQuery.
Check out the post for more details, but here is the function:
jQuery.expr[':'].asp = function(elem, i, match) { return (elem.id && elem.id.match(match[3] + "$")); }; $(":asp(txtPhoneNumber)").keyup(...);
December 10th, 2009 at 7:29 pm
Interesting affair, didn’t thought this would be so awesome when I saw your link!!