sof_engi08
sof_engi08

Reputation: 27

How to check whether a LinkButton is clicked or not

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

Answers (2)

Glen Hughes
Glen Hughes

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

Michael Robinson
Michael Robinson

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")
    }
});

event.target

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

Related Questions