Let me tell you in detail what and how I have tested.
Environment - Firefox, Visual Studio 2010.
Code -
1.
aspx -
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function Change(obj, evt) {
if (evt.type == "focus") {
obj.style.borderColor = "blue";
obj.style.backgroundColor = "Aqua";
}
else if (evt.type == "blur") {
obj.style.borderColor = "black";
obj.style.backgroundColor = "white";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtAccountNoCredit"
runat="server"
CssClass="Text"
AutoPostBack="true"
MaxLength="10"
onblur="Change(this, event)"
onfocus="Change(this, event)"
OnTextChanged="txtCustomerCodeCredit_OnTextChanged">
</asp:TextBox>
<asp:TextBox ID="txt1"
runat="server"
CssClass="Text"
AutoPostBack="true"
MaxLength="10"
OnTextChanged="txt1_OnTextChanged"
onblur="Change(this, event)"
onfocus="Change(this, event)">
</asp:TextBox>
</div>
</form>
</body>
</html>
2.
aspx.cs -
protected void txt1_OnTextChanged(object sender, EventArgs e)
{
Response.Write("Text Changed Called.");
}
protected void txtCustomerCodeCredit_OnTextChanged(object sender, EventArgs e)
{
txt1.Focus();
}
Test Cases -
1.
Focus out from first textbox
-> Moved focus from textbox
txtAccountNoCredit
(Pressed tab key).
->
txtCustomerCodeCredit_OnTextChanged
is getting called.
-> Now, second textbox
txt1
is focused.
-> Entered some text and pressed tab again (or clicked outside the textbox) to focus out from this textbox.
->
txt1_OnTextChanged
is getting called and "Text Changed Called." is getting printed.
2.
Clicking on form and focusing on the textbox
-> Clicked anywhere on the form.
-> Then clicked on the second textbox
txt1
.
-> Entered some text and pressed tab again (or clicked outside the textbox) to focus out from this textbox.
->
txt1_OnTextChanged
is getting called and "Text Changed Called." is getting printed.
Conclusion -
So, this is working fine.
Note -
Let me tell you something.
Refer -
TextBox.TextChanged Event[
^], which says...
The TextChanged event is raised when the content of the text box changes between posts to the server.
For instance -
1. If you just focus into the textbox and then focus out immediately without entering anything, then the
OnTextChanged
will not be called.
So, make sure you change something with the content of the textbox before focusing out.
2. You have some text "abcd" in the textbox already. You focused in and changed nothing, but focusing out, then also the
OnTextChanged
will not be called.
Please test and check thoroughly, then let me know.
Thanks,
Tadit