0

I have two asp buttons in my form in asp. When I click on any of the submit buttons the function below is called which eventually calls callotherfunction().

  $("form").live("submit", function() { 
    callotherfunction();
});

I want to distinguish between the clicks and I want to run the callotherfunction(); only for 1 button.

These are my two submit buttons:

<asp:Button ID="btn1" runat="server" OnClick="Button1_Click" Text="Start Search" />      
<asp:Button ID="btn2" runat="server" OnClick="Button2_Click" Text="Export Data to Excel" />  

i have already tried identifying the button click bny using the code:

$("input").click(function() { 
alert($(this).attr('id'));
});

I dont get any alert. How should I go about the process.

Smern
  • 18,746
  • 21
  • 72
  • 90
Ankita
  • 83
  • 2
  • 15
  • 3
    Want to show your relevant rendered HTML? Your `$("input").click(function() {` should work fine. – tymeJV Jun 27 '13 at 15:06
  • yes Even I thought so.But it is giving me no alert and no error.Is there any other way to get the id of the submit button that is clicked? – Ankita Jun 27 '13 at 15:16
  • Can you post the HTML, right now we can only speculate on why this isn't working. – tymeJV Jun 27 '13 at 15:18
  • 2
    live was deprecated in 1.7 and removed in 1.9. Do not use it. Instead learn to use `on()` – epascarello Jun 27 '13 at 15:18
  • 1
    possible duplicate of [jQuery: how to get which button was clicked upon form submission?](http://stackoverflow.com/questions/5721724/jquery-how-to-get-which-button-was-clicked-upon-form-submission) – epascarello Jun 27 '13 at 15:20
  • these are my two submit buttons – Ankita Jun 27 '13 at 15:20

2 Answers2

0
$("#<%=btn1.ClientID %>").click(function() { ...});

something like this

Alexan
  • 8,165
  • 14
  • 74
  • 101
0

this code worked for me!

 $(document).ready(function () {
        $("input[id$='btn1']").click(function () {
            alert("button1");
        });
    });
Ankita
  • 83
  • 2
  • 15