Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#<%=TextBox1.ClientID %>').focusout(function() {
                alert('textbox change');
            });
            $('#<%=Button1.ClientID %>').click(function() {
                alert('button click');
            });

        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>



Please see the following scenario

Change the textbox value and click the button.
Only text change event is firing, button click event is not firing.
(Both events are not firing simultaneously.)
Posted

Despite the fact that you are clicking the button, but in reality, the button is not getting clicked, because, the focusout() event is getting fired, which is showing an alert() message box (Which is not allowing to fire the button click() event)

To verify this, you can comment out the alert within the focusout() event as follows and see what happens:

JavaScript
<script type="text/javascript">
       $(document).ready(function() {
           $('#<%=TextBox1.ClientID %>').focusout(function() {
               //alert('textbox change');
           });
           $('#<%=Button1.ClientID %>').click(function() {
               alert('button click');
           });
       });
</script>


This time, the "button click" alert message will be shown.

I hope, this helped you.
 
Share this answer
 
Comments
Dalek Dave 6-Jan-11 3:41am    
Very Good Answer, have 5 for that.
When the first alert is showed, the script is break, so the second statement is cannot reach. Please try the following script to verify about that:
XML
<script type="text/javascript">
$(document).ready(function() {
            $('#<%=TextBox1.ClientID %>').focusout(function() {
                document.write('textbox change');
            });
            $('#<%=Button1.ClientID %>').click(function() {
                document.write('button click');
            });
        });
</script>
 
Share this answer
 
v2
Comments
Dalek Dave 6-Jan-11 3:41am    
Good Call.
jerrykid 6-Jan-11 4:21am    
Thanks, Dalek Dave :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900