Connecting Tech Pros Worldwide Forums | Help | Site Map

Focus Control Error After Validation Summary

Newbie
 
Join Date: Jun 2007
Posts: 5
#1: Jun 13 '07
Hi,

Does anyone have an idea of how to set focus to the first control after summary validation occurs. After clicking on the summary validation message box, the focus should be set to the first control that causes an error.

I am using asp.net and javascripts.So I am trying to solve the problem with a javascript.

Help!

Thanks

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,131
#2: Jun 13 '07

re: Focus Control Error After Validation Summary


Quote:

Originally Posted by Luke Sayaw

Hi,

Does anyone have an idea of how to set focus to the first control after summary validation occurs. After clicking on the summary validation message box, the focus should be set to the first control that causes an error.

I am using asp.net and javascripts.So I am trying to solve the problem with a javascript.

Help!

Thanks

Hi Luke!

You will need to register a hidden field and set it to the control that caused the error.

Eg:
Expand|Select|Wrap|Line Numbers
  1.  Me.Page.ClientScript.RegisterHiddenField("__InvalidCtrl", TXT_TextBoxControl.ClientID)
Then in your javascript:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. document.getElementById(__InvalidCtr).focus();
  3.  
  4.  
You'll have to put in try catch blocks in case there is no control that was invalid...that way you aren't trying to set a null control's focus...

Hope this gets you pointed in the right direction!

-Frinny
Newbie
 
Join Date: Jun 2007
Posts: 5
#3: Jun 13 '07

re: Focus Control Error After Validation Summary


Hi Frinny,

Thanks for the solution. I ll apply the script as suggested and hope that it ll solve the problem.
Reply


Similar .NET Framework bytes