Reputation: 27
I have a LinkButton
as
<asp:LinkButton ID="lnkbuton" runat="server" OnClick="lnck" Text="hello">
Actually I have a LinkButton and a TabContainer with two tabs. When a user clicks on the tab I am clearing the data in the GridView, but when the user clicks on the LinkButton I don't want to clear the data. Thus, I want to find if the LinkButton is clicked or not.
I did something like this.
function onBeginRequest(sender, args) {
$(document).ready(function(){
var shHide = "0";
$("#lnkbuton").click(function() {
shHide="1";
alert("clcik")
});
if (shHide == "0") {
ClearHideElement();
}
})
}
But this is not working. Also the alert never gets executed.
Upvotes: 0
Views: 916
Reputation: 4812
Controls within an aspx page generate their own ID, they don't always use the ID you give them: http://msdn.microsoft.com/en-us/library/1d04y8ss.aspx
Try this instead:
$("#<%= lnkbuton.ClientID %>").click(function() {
shHide="1";
alert("clcik")
});
Upvotes: 2
Reputation: 29498
Check the event's target, if it isn't the anchor
, perform your action.
$("#lnkbuton").click(function(event) {
if (event.target != this) {
shHide="1";
alert("clcik")
}
});
The target property can be the element that registered for the event or a descendant of it. It is often useful to compare event.target to this in order to determine if the event is being handled due to event bubbling. This property is very useful in event delegation, when events bubble.
Upvotes: 0