Onblur()/ Lost focus

I have 2 textboxes in a webform one and two.  The code below works correctly to setfocus on textbox one.  
The code also works correctly when the value of textbox one changes.

But the code doesn't work if I tab to textbox two from textbox one.  In other words I want the code to call textchanged event when textbox one loses focus(onblur doesn't work).  

Please someone help me.

I have the following code:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="test.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<Script runat="server">
void one_TextChanged(object sender, System.EventArgs e)
            {
                  two.Text = code();
            }
   private string code()
            {
                  return "won";
            }
</Script>

<HTML>
      <HEAD>
            <title>WebForm1</title>
      </HEAD>
      
<body onload="document.forms[0].one.focus();">
<form id="Form1" method="post" runat="server">

<asp:TextBox id="one" onblur="one_TextChanged;document.forms[0].submit()"  runat="server" Width="210px"
Height="46px"AutoPostBack="True"></asp:TextBox>
<asp:TextBox id="two" runat="server" Height="44px"></asp:TextBox>
            
</form>
/body>
</HTML>
miyengarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

surajgupthaCommented:
I think there might be a small mixup with aspx and javascript

"void one_TextChanged(object sender, System.EventArgs e)" is aspx code

and

"document.forms[0].submit()" is javascript
0
miyengarAuthor Commented:
What is the solution?
0
surajgupthaCommented:
<asp:TextBox id="one" onblur="one_TextChanged()"  runat="server" Width="210px"
Height="46px" ></asp:TextBox>

<Script runat="server">
funtion one_TextChanged()
          {
               document.all.two.value = code();
          }
   function code()
          {
               return "won";
          }
</Script>
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

miyengarAuthor Commented:
Comment added by surajguptha does not work. Again there is conflict b/n asp and javascript.
I am using Visual studio IDE
0
surajgupthaCommented:
Following is an example that works. :-)
Please let me know if it works


<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="test.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" Content="C#">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
            <script language=javascript>
            function Changed()
            {                               
                   document.all.two.value = code();
            }
            
            function code()
            {
                  return "won";
            }
            </script>
      </HEAD>
      <body onload="document.forms[0].one.focus();">
            <form id="Form1" method="post" runat="server">
                  <asp:TextBox id="one" runat="server" onblur="Changed()"></asp:TextBox>
                  <asp:TextBox id="two" runat="server"></asp:TextBox>
            </form>
      </body>
</HTML>
0
miyengarAuthor Commented:
The above code works fine.  But if i have to call asp.net code like text_changed() event then how to use it in onblur()?
like for example:
I want onblur to call this asp.net/c# code
private void code()
{
two.Text = "won";
}
0
surajgupthaCommented:
If u want text changed event to occur on the server side.

<asp:TextBox id="one" runat="server" AutoPostBack="True"></asp:TextBox>

1) Goto Design view
2) Click on the textbox for which u want the textchanged event to occur
3) Click f4 for properties
4) There u will see a lightning icon, click it
5) There you will find ontextchanged. Double click it. Then you will get a function
6) In that function type the following line

two.Text="Won";

That should work
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.