asp.net - Select .net control by string containing in jquery -
i working in asp.net , have 2 imagebuttons this:
<asp:imagebutton runat="server" id="hosciz" imageurl="../image/ciz1.png" width="20px"height="20px" alternatetext="bla bla" /> <asp:imagebutton runat="server" id="hosciz2" imageurl="../image/ciz1.png" width="20px"height="20px" alternatetext="bla bla again" />
like see both imagebutton ids contains 'hosciz' string wonder can use .each() function id containing. know there
$("div[id*='hosciz']").each(function(){.....});
is there way imagebuttons or other .net controls instead of html control div ? mean there sould be, how ?
i know can solve
$("#<%=hosciz.clientid%>").click(function(){ 'do whatever want' }); $("#<%=hosciz2.clientid%>").click(function(){ 'do whatever want' });
but said wonder if there way each() function ?
use class attribute on image:
<asp:imagebutton runat="server" cssclass="hosciz" id="hosciz" imageurl="../image/ciz1.png" width="20px"height="20px" alternatetext="bla bla" /> <asp:imagebutton runat="server" cssclass="hosciz" id="hosciz2" imageurl="../image/ciz1.png" width="20px"height="20px" alternatetext="bla bla again" />
and in jquery class selector
$(".hosciz").each(function(){.....});
or
$("div.hosciz").each(function(){.....});
it has added bonus of allowing common style in css image.
alternatively, use clientidmode="static", ensure id in html matches asp clisentid. of course come other problems - you'll need make id unique, comes performance boost in html selectors.
<asp:imagebutton runat="server" clientidmode="static" id="hosciz" imageurl="../image/ciz1.png" width="20px"height="20px" alternatetext="bla bla" /> <asp:imagebutton runat="server" clientidmode="static" id="hosciz2" imageurl="../image/ciz1.png" width="20px"height="20px" alternatetext="bla bla again" />
and in jquery,
$("#hosciz, #hosciz2").each(function(){.....});
Comments
Post a Comment