Monday, March 26, 2012

Shift/set focus on textboxes in ASP.NET

Hi,

I have a webform in which the user is required to input his tel. no. Now when the user enters the area code i would like the focus to shift to the tel. no. textbox. Is there any way cursor focus can be shifted from one textbox to another in ASP.NET pages.

Also is it possible to format the way the tel. no. textbox is displayed like for ex. XXX-XXXX (with the dash in the middle).

Thanks in advance for the help.Yes... use javascript. Control focus on the client side has nothing to do with ASP.NET, because ASP.NET is not a client-side technology, its a server-side technology.
So... its like this...

If you have two textboxes on a web page...

In the VB code-behind, you simply add an attribute called 'onBlur' to the first textbox.

Private Sub Page_Load
Me.TextBox1.Attributes.Add("onBlur","document.getElementById('TextBox2').focus();")
End Sub

0 comments:

Post a Comment