Saturday, March 24, 2012

Set focus on a text box

Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
SwamiOne way is to handle the onBlur event of the text box:
<asp:TextBox runat="server" id="txt" onblur="if (this.value.replace(/\s/g,
'').length == 0) this.focus();">
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
Swami
The easiest, most reliable way is client side java script:
MyControl.focus();
Here's more info:
http://wp.netscape.com/eng/mozilla/...f_f-g.htm#59872
You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
> two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
> apart
> from displaying the error message. Please help.
> Regards,
> Swami
Check out this code snippet,
http://www.extremeexperts.com/Net/C...ck.
aspx
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
apart
> from displaying the error message. Please help.
> Regards,
> Swami

0 comments:

Post a Comment