How to set focus on error location in asp.net c#

S

Sukh

Hi,
I am working on a form page (asp.net + c#). form is too long and in
some cases we are validating it server side, if there is some invalid
data in text box then form return from server side and we are displying
the form again. but it's not displaying the exact location where the
error occur. user has to scroll it up or down to see the error. Can any
body help me to set the focus on the same place where error occur. I
want to do it at server side in C#.
Thanks in advance.
Sukh.
 
S

S. Justin Gengo

Sukh,

I've created a ScrollToElement javascript that will do exactly what you
need. It's available as part of a Javascript component project I've made
available on my website. All the code on my site is free for any use. I've
also created a helpfile to show how to use the components on the website.
You may download the Javascript component for free by going to
www.aboutfortunate.com, clicking the "Code Library" link at the top left of
the page. And then clicking on the "Javascript" button which will appear in
the menu on the left.

Please let me know if you have any questions about the component.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
R

rviray

I don't know if you could set focus of the client side/HTM
object....but, you could do it on the client side...

1) Create an HTMLInputHidden text box
2) Create a javascript function that will read the hidden field t
indicate what field to set focus on. (i.e.
document.getElementByID(document.getElementByID(<your hidden fiel
ID>).value).focus() <-- something like that...
3) add the Javascript function call on the onLoad event of the body
4) On server side validation, insert the ID or Name of the field tha
did not pass validation....

try that..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top