Tuesday, 24 March 2009

ASP.NET control referencing in jquery

ASP.NET controls often render with client-side IDs different than what's declared in your aspx code.

If your using jquery the easiest way is to use the [attribute$=value] method - an example to get the aspx made link id, from your coded id:

//include jquery.js then:
$(document).ready(function(){$("a[id$='login_link']").click(function(event){tester(event,this)});});
function tester(event, el){
event.preventDefault();
alert($(el).attr("id"));
}

//for element:

No comments: