Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Onblur()/ Lost focus

Posted on 2004-11-03
8
Medium Priority
?
4,420 Views
Last Modified: 2012-08-14
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>
0
Comment
Question by:miyengar
  • 4
  • 3
8 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 12489878
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
 

Author Comment

by:miyengar
ID: 12493102
What is the solution?
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 12493151
<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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:riyasjef
ID: 12493746
0
 

Author Comment

by:miyengar
ID: 12494841
Comment added by surajguptha does not work. Again there is conflict b/n asp and javascript.
I am using Visual studio IDE
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 12500881
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
 

Author Comment

by:miyengar
ID: 12507685
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
 
LVL 21

Accepted Solution

by:
surajguptha earned 200 total points
ID: 12508289
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question