![]() |
Web Development »
Validation »
General
Intermediate
Transferring Control Focus through Custom Validation File, in ASP.NETBy bkalicharanValidation controls will not set the focus to the appropriate control when the validation fails. This can be achieved using a custom validation file. |
Javascript, XML, Windows, .NET, ASP.NET, Visual Studio, WebForms, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
In one of my recent projects, I faced the problem of how to transfer control focus to the appropriate control when validation fails. I was confused with the client requirement at first but realized it is a common and basic requirement from the user point. But it is not implemented in the WebUIValidation.js. You can implement this with a minimal setting change in the web.config file and a little code change in the WebUIValidation file.
Add the following element in the system.web section of the web.config file for using a custom validation file:
<webControls clientScriptsLocation="<virtual_path>/javascripts/"></webControls>
Add a new function in the WebUIValidation which will set the focus to the control which fails in the validation process.
function ValidatorControlFocus()
{
if(typeof(Page_Validators) != "undefined")
{
for (i = 0; i < Page_Validators.length; i++)
{
val = Page_Validators[i];
if(val.isvalid == false)
{
control = document.all[val.controltovalidate];
if(control != null)
{
if( !control.isDisabled ){
if(control.style.visibility != "hidden"){
control.focus();
}
}
return;
}
}
}
}
}
Call the above function in Page_ClientValidate as well as in ValidatorCommonOnSubmit functions.
| You must Sign In to use this message board. | |||||
|
|||||
|
|||||
|
|||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 12 May 2005 Editor: Smitha Vijayan |
Copyright 2005 by bkalicharan Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |