below is some sample code from my .ascx pages,i am trying to use jquery to perform someaction, $("input") served me well but $("asp:Label") is not working. what should I include inorder to make $("asp:Label") work
<asp:Label ID="lblInvolvedMembers" runat="server"></asp:Label>
<asp:Label ID="lblAcceptedBy" runat="server"> </asp:Label>
<input type="text" id="family" value="family " />
<input type="button" id="family1" value="button" />
//here i am trying to get server control to perform some action, $("input") served me well but $("asp:Label") is not working. what should i include inorder to make $("asp:Label") work
$("asp:Label").hover(function() {
Tip.text('');
var ToolTipID = $(this).attr('id');
var height = $(this).height() + 10;
var offset = $(this).offset();
if (data[ToolTipID].split('<br\>').length - 1) {
var temp = data[ToolTipID].split('<br\>').length - 1;
height = temp * 10;
} else {
height = 10;
}
$("input").hover(function() {
Tip.text('');
var ToolTipID = $(this).attr('id');
var height = $(this).height() + 10;
var offset = $(this).offset();
if (data[ToolTipID].split('<br\>').length - 1) {
var temp = data[ToolTipID].split('<br\>').length - 1;
height = temp * 10;
} else {
height = 10;
}
you'll want to change
<asp:Label ID="lblInvolvedMembers" runat="server"></asp:Label>
to something like
<asp:Label ID="lblInvolvedMembers" runat="server" CssClass="label"></asp:Label>
then you can use the jQuery selector here
$('.label').hover(function() {
instead of
$("asp:Label").hover(function() {
that way, all the labels will have the jQuery hover function.
if you wanted a specific label to be hovered, you'd have to use
$('#<%= lblInvolvedMembers.ClientID %>').hover(function() {
ASP tags are processed before being passed to the client browser where javascript can act on them, hence
lblInvolvedMembers would become something like ctl0_label_lblInvolvedMembers or something.
UPDATE
it also looks like you haven't closed your jQuery functions
$('.label').hover(function() {
Tip.text('');
var ToolTipID = $(this).attr('id');
var height = $(this).height() + 10;
var offset = $(this).offset();
if (data[ToolTipID].split('<br\>').length - 1) {
var temp = data[ToolTipID].split('<br\>').length - 1;
height = temp * 10;
} else {
height = 10;
}
});
$("input").hover(function() {
Tip.text('');
var ToolTipID = $(this).attr('id');
var height = $(this).height() + 10;
var offset = $(this).offset();
if (data[ToolTipID].split('<br\>').length - 1) {
var temp = data[ToolTipID].split('<br\>').length - 1;
height = temp * 10;
} else {
height = 10;
}
});
I am not sure what Tip and data are, but you can see a working .hover() function on this jsFiddle -> http://jsfiddle.net/XF4Zk/ the IDs of the labels here represent a clientside id of the control created by ASP.NET, which is why you would use lblInvolvedMembers.ClientID to get the value of the control for Javascript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With