473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Setting Focus on field when RequiredFieldValidator fails - This Works!

There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There are a couple of people selling components... but that is not really an option for me... So, I took the plunge and modified the "WebUIValidation.js" file to make it happen... After tracing through file, I figure it out. It was actually pretty easy... I am really surprised that Microsoft did not include this functionality by default... anyway, here is the solution and code for you all to tweak.. :-)

1.. Create an ASP.NET web application in C#
2.. Create some form elements
3.. Drag a RequiredFieldValidator next to one of your fields
4.. Build and browse
5.. In your browser, view the html source code.
6.. Search for a string in the source code called "WebUIValidation.js" and take a note of the full path. You will need to open this file in the next step. For example, my full path was...

C:\Inetpub\wwwroot\aspnet_client/system_web/1_0_3705_288/WebUIValidation.js

7.. So, go ahead and open the file from step 6: "WebUIValidation.js" *** Make a backup first (just in case!)
8.. We are only going to modify the "ValidatorUpdateIsValid()" function. Modify the function to look like the following (I have included the entire function here... so you can actually just overwrite yours with this one):
function ValidatorUpdateIsValid() {

var i;

for (i = 0; i < Page_Validators.length; i++) {
if (!Page_Validators[i].isvalid) {

Page_IsValid = false;
//---[ YERKES * 06/29/03 ]--------------------------------------

// The code in this function was added to allow field

// focusing when a validator is not valid.

//

// Uncomment the following 'alert' if you want a pop-up

// to display the error message along with it being dispalyed

// on the form.

//--------------------------------------------------------------

//alert(Page_Validators[i].errormessage);
var strControlToValidate = Page_Validators[i].controltovalidate;

var strControlType = document.forms[0].elements[strControlToValidate].type;

if (strControlType != "text"){

document.forms[0].elements[strControlToValidate][0].focus();

return
} else {

document.forms[0].elements[strControlToValidate].focus();

return;

}

}

}

Page_IsValid = true;

}
9.. Save this File and "refesh" your aspx page in the browser. The changes should have taken effect.
That's it... this works for text fields and radiobuttonlists... that is all I have tested but it should set focus to any field if it fails any validation for any reason (and not submt the form, of course).

I have also attached my WebUIValidation.js just so you can have the whole thing.. but like I said, we only added a couple lines of code to 1 function... not bad. :-)

Peace out and remember.. J2EE is for punks..

Nov 17 '05 #1
3 8292
Hi,
I tried this and receive an error message from a part of the code that
i'm not messing with at all....

yh*****@online.microsoft.com (Yan-Hong Huang[MSFT]) wrote in message news:<Xj**************@cpmsftngxa09.phx.gbl>...
Hello Steve,

Thanks very much for the post in the group. I will look into it and file
this into our knowlege base database. We are looking at continual
improvement in VS.NET, and it's this kind of feedback that let's us know
what things you're trying to do, that we haven't yet exposed for you.

Thanks again and hope you enjoy the group.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
--------------------
!From: "Steve Yerkes" <st**********@health.net>
!Subject: Setting Focus on field when RequiredFieldValidator fails - This
Works!
!Date: Sun, 29 Jun 2003 04:24:36 -0700
!Lines: 759
!MIME-Version: 1.0
!Content-Type: multipart/mixed;
! boundary="----=_NextPart_000_000B_01C33DF6.5957C7C0"
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
!Message-ID: <ut**************@TK2MSFTNGP11.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: adsl-63-204-75-83.dsl.scrm01.pacbell.net 63.204.75.83
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:155675
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!There seems to be way too much confusion over how to set focus on the a
field using a field validator. I looked all over the web and found people
trying to do this, but not getting anywhere. There are a couple of people
selling components... but that is not really an option for me... So, I
took the plunge and modified the "WebUIValidation.js" file to make it
happen... After tracing through file, I figure it out. It was actually
pretty easy... I am really surprised that Microsoft did not include this
functionality by default... anyway, here is the solution and code for you
all to tweak.. :-)
! 1.. Create an ASP.NET web application in C#
! 2.. Create some form elements
! 3.. Drag a RequiredFieldValidator next to one of your fields
! 4.. Build and browse
! 5.. In your browser, view the html source code.
! 6.. Search for a string in the source code called "WebUIValidation.js"
and take a note of the full path. You will need to open this file in the
next step. For example, my full path was...
!
C:\Inetpub\wwwroot\aspnet_client/system_web/1_0_3705_288/WebUIValidation.js
! 7.. So, go ahead and open the file from step 6: "WebUIValidation.js" ***
Make a backup first (just in case!)
! 8.. We are only going to modify the "ValidatorUpdateIsValid()" function.
Modify the function to look like the following (I have included the entire
function here... so you can actually just overwrite yours with this one):
! function ValidatorUpdateIsValid() {
! var i;
! for (i = 0; i < Page_Validators.length; i++) {
! if (!Page_Validators[i].isvalid) {
! Page_IsValid = false;
! //---[ YERKES * 06/29/03 ]--------------------------------------
! // The code in this function was added to allow field
! // focusing when a validator is not valid.
! //
! // Uncomment the following 'alert' if you want a pop-up
! // to display the error message along with it being dispalyed
! // on the form.
! //--------------------------------------------------------------
! //alert(Page_Validators[i].errormessage);
! var strControlToValidate = Page_Validators[i].controltovalidate;
! var strControlType =
document.forms[0].elements[strControlToValidate].type;
! if (strControlType != "text"){
! document.forms[0].elements[strControlToValidate][0].focus();
! return
! } else {
! document.forms[0].elements[strControlToValidate].focus();
! return;
! }
! }
! }
! Page_IsValid = true;
! }
! 9.. Save this File and "refesh" your aspx page in the browser. The
changes should have taken effect.
!That's it... this works for text fields and radiobuttonlists... that is
all I have tested but it should set focus to any field if it fails any
validation for any reason (and not submt the form, of course).
!I have also attached my WebUIValidation.js just so you can have the whole
thing.. but like I said, we only added a couple lines of code to 1
function... not bad. :-)
!Peace out and remember.. J2EE is for punks..
!

Nov 17 '05 #2
Hello Alan,

I think you could contact Steve in the group or email to see if he could provide more info. I suggest you provide detailed error
message and the info that where the error happened. Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: al**********@yahoo.com (Alan)
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Subject: Re: Setting Focus on field when RequiredFieldValidator fails - This Works!
!Date: 31 Jul 2003 11:50:51 -0700
!Organization: http://groups.google.com/
!Lines: 103
!Message-ID: <83**************************@posting.google.com >
!References: <ut**************@TK2MSFTNGP11.phx.gbl> <Xj**************@cpmsftngxa09.phx.gbl>
!NNTP-Posting-Host: 12.150.117.131
!Content-Type: text/plain; charset=ISO-8859-1
!Content-Transfer-Encoding: 8bit
!X-Trace: posting.google.com 1059677452 4261 127.0.0.1 (31 Jul 2003 18:50:52 GMT)
!X-Complaints-To: gr**********@google.com
!NNTP-Posting-Date: 31 Jul 2003 18:50:52 GMT
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-online.de!news-spur1.maxwell.syr.edu!
news.maxwell.syr.edu!sn-xit-03!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:163885
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Hi,
!I tried this and receive an error message from a part of the code that
!i'm not messing with at all....
!
!y******@online.microsoft.com (Yan-Hong Huang[MSFT]) wrote in message news:<Xj1VtJ5PDHA.1272
@cpmsftngxa09.phx.gbl>...
!> Hello Steve,
!>
!> Thanks very much for the post in the group. I will look into it and file
!> this into our knowlege base database. We are looking at continual
!> improvement in VS.NET, and it's this kind of feedback that let's us know
!> what things you're trying to do, that we haven't yet exposed for you.
!>
!> Thanks again and hope you enjoy the group.
!>
!> Best regards,
!> yhhuang
!> VS.NET, Visual C++
!> Microsoft
!>
!> This posting is provided "AS IS" with no warranties, and confers no rights.
!> Got .Net? http://www.gotdotnet.com
!> --------------------
!> !From: "Steve Yerkes" <st**********@health.net>
!> !Subject: Setting Focus on field when RequiredFieldValidator fails - This
!> Works!
!> !Date: Sun, 29 Jun 2003 04:24:36 -0700
!> !Lines: 759
!> !MIME-Version: 1.0
!> !Content-Type: multipart/mixed;
!> ! boundary="----=_NextPart_000_000B_01C33DF6.5957C7C0"
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
!> !Message-ID: <ut**************@TK2MSFTNGP11.phx.gbl>
!> !Newsgroups: microsoft.public.dotnet.framework.aspnet
!> !NNTP-Posting-Host: adsl-63-204-75-83.dsl.scrm01.pacbell.net 63.204.75.83
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
!> !Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:155675
!> !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!> !
!> !There seems to be way too much confusion over how to set focus on the a
!> field using a field validator. I looked all over the web and found people
!> trying to do this, but not getting anywhere. There are a couple of people
!> selling components... but that is not really an option for me... So, I
!> took the plunge and modified the "WebUIValidation.js" file to make it
!> happen... After tracing through file, I figure it out. It was actually
!> pretty easy... I am really surprised that Microsoft did not include this
!> functionality by default... anyway, here is the solution and code for you
!> all to tweak.. :-)
!> ! 1.. Create an ASP.NET web application in C#
!> ! 2.. Create some form elements
!> ! 3.. Drag a RequiredFieldValidator next to one of your fields
!> ! 4.. Build and browse
!> ! 5.. In your browser, view the html source code.
!> ! 6.. Search for a string in the source code called "WebUIValidation.js"
!> and take a note of the full path. You will need to open this file in the
!> next step. For example, my full path was...
!> !
!> C:\Inetpub\wwwroot\aspnet_client/system_web/1_0_3705_288/WebUIValidation.js
!> ! 7.. So, go ahead and open the file from step 6: "WebUIValidation.js" ***
!> Make a backup first (just in case!)
!> ! 8.. We are only going to modify the "ValidatorUpdateIsValid()" function.
!> Modify the function to look like the following (I have included the entire
!> function here... so you can actually just overwrite yours with this one):
!> ! function ValidatorUpdateIsValid() {
!> ! var i;
!> ! for (i = 0; i < Page_Validators.length; i++) {
!> ! if (!Page_Validators[i].isvalid) {
!> ! Page_IsValid = false;
!> ! //---[ YERKES * 06/29/03 ]--------------------------------------
!> ! // The code in this function was added to allow field
!> ! // focusing when a validator is not valid.
!> ! //
!> ! // Uncomment the following 'alert' if you want a pop-up
!> ! // to display the error message along with it being dispalyed
!> ! // on the form.
!> ! //--------------------------------------------------------------
!> ! //alert(Page_Validators[i].errormessage);
!> ! var strControlToValidate = Page_Validators[i].controltovalidate;
!> ! var strControlType =
!> document.forms[0].elements[strControlToValidate].type;
!> ! if (strControlType != "text"){
!> ! document.forms[0].elements[strControlToValidate][0].focus();
!> ! return
!> ! } else {
!> ! document.forms[0].elements[strControlToValidate].focus();
!> ! return;
!> ! }
!> ! }
!> ! }
!> ! Page_IsValid = true;
!> ! }
!> ! 9.. Save this File and "refesh" your aspx page in the browser. The
!> changes should have taken effect.
!> !That's it... this works for text fields and radiobuttonlists... that is
!> all I have tested but it should set focus to any field if it fails any
!> validation for any reason (and not submt the form, of course).
!> !I have also attached my WebUIValidation.js just so you can have the whole
!> thing.. but like I said, we only added a couple lines of code to 1
!> function... not bad. :-)
!> !Peace out and remember.. J2EE is for punks..
!> !
!
Nov 17 '05 #3
Hello Alan,

I think you could contact Steve in the group or email to see if he could provide more info. I suggest you provide detailed error
message and the info that where the error happened. Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: al**********@yahoo.com (Alan)
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Subject: Re: Setting Focus on field when RequiredFieldValidator fails - This Works!
!Date: 31 Jul 2003 11:50:51 -0700
!Organization: http://groups.google.com/
!Lines: 103
!Message-ID: <83**************************@posting.google.com >
!References: <ut**************@TK2MSFTNGP11.phx.gbl> <Xj**************@cpmsftngxa09.phx.gbl>
!NNTP-Posting-Host: 12.150.117.131
!Content-Type: text/plain; charset=ISO-8859-1
!Content-Transfer-Encoding: 8bit
!X-Trace: posting.google.com 1059677452 4261 127.0.0.1 (31 Jul 2003 18:50:52 GMT)
!X-Complaints-To: gr**********@google.com
!NNTP-Posting-Date: 31 Jul 2003 18:50:52 GMT
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-online.de!news-spur1.maxwell.syr.edu!
news.maxwell.syr.edu!sn-xit-03!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:163885
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Hi,
!I tried this and receive an error message from a part of the code that
!i'm not messing with at all....
!
!y******@online.microsoft.com (Yan-Hong Huang[MSFT]) wrote in message news:<Xj1VtJ5PDHA.1272
@cpmsftngxa09.phx.gbl>...
!> Hello Steve,
!>
!> Thanks very much for the post in the group. I will look into it and file
!> this into our knowlege base database. We are looking at continual
!> improvement in VS.NET, and it's this kind of feedback that let's us know
!> what things you're trying to do, that we haven't yet exposed for you.
!>
!> Thanks again and hope you enjoy the group.
!>
!> Best regards,
!> yhhuang
!> VS.NET, Visual C++
!> Microsoft
!>
!> This posting is provided "AS IS" with no warranties, and confers no rights.
!> Got .Net? http://www.gotdotnet.com
!> --------------------
!> !From: "Steve Yerkes" <st**********@health.net>
!> !Subject: Setting Focus on field when RequiredFieldValidator fails - This
!> Works!
!> !Date: Sun, 29 Jun 2003 04:24:36 -0700
!> !Lines: 759
!> !MIME-Version: 1.0
!> !Content-Type: multipart/mixed;
!> ! boundary="----=_NextPart_000_000B_01C33DF6.5957C7C0"
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
!> !Message-ID: <ut**************@TK2MSFTNGP11.phx.gbl>
!> !Newsgroups: microsoft.public.dotnet.framework.aspnet
!> !NNTP-Posting-Host: adsl-63-204-75-83.dsl.scrm01.pacbell.net 63.204.75.83
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
!> !Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:155675
!> !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!> !
!> !There seems to be way too much confusion over how to set focus on the a
!> field using a field validator. I looked all over the web and found people
!> trying to do this, but not getting anywhere. There are a couple of people
!> selling components... but that is not really an option for me... So, I
!> took the plunge and modified the "WebUIValidation.js" file to make it
!> happen... After tracing through file, I figure it out. It was actually
!> pretty easy... I am really surprised that Microsoft did not include this
!> functionality by default... anyway, here is the solution and code for you
!> all to tweak.. :-)
!> ! 1.. Create an ASP.NET web application in C#
!> ! 2.. Create some form elements
!> ! 3.. Drag a RequiredFieldValidator next to one of your fields
!> ! 4.. Build and browse
!> ! 5.. In your browser, view the html source code.
!> ! 6.. Search for a string in the source code called "WebUIValidation.js"
!> and take a note of the full path. You will need to open this file in the
!> next step. For example, my full path was...
!> !
!> C:\Inetpub\wwwroot\aspnet_client/system_web/1_0_3705_288/WebUIValidation.js
!> ! 7.. So, go ahead and open the file from step 6: "WebUIValidation.js" ***
!> Make a backup first (just in case!)
!> ! 8.. We are only going to modify the "ValidatorUpdateIsValid()" function.
!> Modify the function to look like the following (I have included the entire
!> function here... so you can actually just overwrite yours with this one):
!> ! function ValidatorUpdateIsValid() {
!> ! var i;
!> ! for (i = 0; i < Page_Validators.length; i++) {
!> ! if (!Page_Validators[i].isvalid) {
!> ! Page_IsValid = false;
!> ! //---[ YERKES * 06/29/03 ]--------------------------------------
!> ! // The code in this function was added to allow field
!> ! // focusing when a validator is not valid.
!> ! //
!> ! // Uncomment the following 'alert' if you want a pop-up
!> ! // to display the error message along with it being dispalyed
!> ! // on the form.
!> ! //--------------------------------------------------------------
!> ! //alert(Page_Validators[i].errormessage);
!> ! var strControlToValidate = Page_Validators[i].controltovalidate;
!> ! var strControlType =
!> document.forms[0].elements[strControlToValidate].type;
!> ! if (strControlType != "text"){
!> ! document.forms[0].elements[strControlToValidate][0].focus();
!> ! return
!> ! } else {
!> ! document.forms[0].elements[strControlToValidate].focus();
!> ! return;
!> ! }
!> ! }
!> ! }
!> ! Page_IsValid = true;
!> ! }
!> ! 9.. Save this File and "refesh" your aspx page in the browser. The
!> changes should have taken effect.
!> !That's it... this works for text fields and radiobuttonlists... that is
!> all I have tested but it should set focus to any field if it fails any
!> validation for any reason (and not submt the form, of course).
!> !I have also attached my WebUIValidation.js just so you can have the whole
!> thing.. but like I said, we only added a couple lines of code to 1
!> function... not bad. :-)
!> !Peace out and remember.. J2EE is for punks..
!> !
!
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
This function validates a price field on my form. It fires with onchange. If the validation fails, I want the focus to return to the same field so that the user can correct it. The way it is...
0
by: JoRo | last post by:
I am working on a project where I want a very user-friendly interface. I have a datagrid of categories that uses the EditCommandColumn to do in-line editing of the category name. On the page is...
3
by: Rick | last post by:
I have an interesting problem when I run the following code in Netscape (7.02) vs. IE. This page works great in IE and all my controls bring up the validation summary dialog box if the required...
0
by: Stimp | last post by:
I have a text box, RequiredFieldValidator for this text box and a button Web Control to submit the page. Is there a way to set the focus of cursor to the text box when the RequiredFieldValidator...
12
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function...
1
by: D. Shane Fowlkes | last post by:
I have a asp:textbox which I've applied a javascript function to strip off all non-numeric chanarcters. The js function is triggered with the textbox's onblur attribute. I also have a...
1
by: Niclas | last post by:
Hi, How do I indicate what field fails a validation, usually you see a red star next to the faild field on a form. Is this built in functionality in the valdaition controls or shall I code this...
3
by: vivela | last post by:
hi, I hope you could help me out on this one,cause I have been trying for 4 days to solve it,but couldn't quite get it right: I have an ASP textbox that should change the value in a dropdownlist....
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.