Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Detect When a Control Gains Focus

Reply
Thread Tools

Detect When a Control Gains Focus

 
 
StinkyDuck
Guest
Posts: n/a
 
      11-15-2007
Is there a way to detect when a control gains focus on a webform? Say I
have two text boxes. After the user types in information on the first text
box and hits the tab key or clicks on the second text box, I want to
automatically fill in the second text box with the information from the
first text box.

I just can't seem to find an event handler for when the control gains/loses
focus.

-StinkyDuck


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      11-15-2007
StinkyDuck,
"focus" is a client-side, in - the - browser event that can be handled with
Javascript. Usually the event name is onfocus. if you are looking to fill in
a second textbox when the user leaves the first, onblur would probably be
more useful.

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



"StinkyDuck" wrote:

> Is there a way to detect when a control gains focus on a webform? Say I
> have two text boxes. After the user types in information on the first text
> box and hits the tab key or clicks on the second text box, I want to
> automatically fill in the second text box with the information from the
> first text box.
>
> I just can't seem to find an event handler for when the control gains/loses
> focus.
>
> -StinkyDuck
>
>
>

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      11-15-2007
You can do it on client side with javascript. Handle onfocus event:

myTextBox2.Attributes["onfocus"] = "myHandler()"

and myHandler will be a javascript function with something like
Form1.myTextBox2.value = Form1.myTextBox1.value;

You may have to refer to the textboxes in some other way depending on where
they are located.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"StinkyDuck" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a way to detect when a control gains focus on a webform? Say I
> have two text boxes. After the user types in information on the first

text
> box and hits the tab key or clicks on the second text box, I want to
> automatically fill in the second text box with the information from the
> first text box.
>
> I just can't seem to find an event handler for when the control

gains/loses
> focus.
>
> -StinkyDuck
>
>



 
Reply With Quote
 
Scott Roberts
Guest
Posts: n/a
 
      11-15-2007
As others have mentioned, JavaScript (onblur/onfocus) is the preferred way.

However, you could set AutoPostBack=true and create a OnChange handler to do
what you want on the server. This approach is riddled with problems and not
recommended, but it is available nonetheless.


"StinkyDuck" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a way to detect when a control gains focus on a webform? Say I
> have two text boxes. After the user types in information on the first
> text box and hits the tab key or clicks on the second text box, I want to
> automatically fill in the second text box with the information from the
> first text box.
>
> I just can't seem to find an event handler for when the control
> gains/loses focus.
>
> -StinkyDuck
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Olympus America Adds Linux, Gains Three Times the Performance technology_post@yahoo.com Digital Photography 1 04-07-2006 11:24 PM
HD DVD Gains Momentum. Allan DVD Video 4 07-03-2005 09:50 PM
HVD Format Gains Backers. Allan DVD Video 2 02-08-2005 01:45 AM
New DVD standard gains support. Allan DVD Video 0 01-18-2004 08:20 PM



Advertisments