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(...);

Tags: , , ,

7 Responses to “Extending jQuery to Select ASP Controls”

  1. Draircart Says:

    Interesting affair, didn’t thought this would be so awesome when I saw your link!!

  2. Grayson Gill Says:

    adding to fav’s

  3. Taryn Hockema Says:

    Someone essentially help to make seriously articles I would state. This is the first time I frequented your website page and thus far? I surprised with the research you made to make this particular publish extraordinary. Fantastic job!

  4. Honey Dealy Says:

    Undeniably believe that which you said. Your favorite reason seemed to be on the internet the simplest thing to be aware of. I say to you, I definitely get annoyed while people consider worries that they just do not know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks

  5. Calista Hattley Says:

    whoah this blog is wonderful i love reading your posts. Keep up the great work! You know, lots of people are looking around for this info, you can aid them greatly.

  6. Scottie Cilek Says:

    I will immediately grab your rss as I can’t find your email subscription link or e-newsletter service. Do you’ve any? Please let me know so that I could subscribe. Thanks.

  7. Facebooksmiles.Facebook-Smiles.com Says:

    I liked

Leave a Reply

Posting Code: Use html such as <pre lang='javascript'></pre>. See all supported languages.

*