Problem Moving to Top of Page When Submit Fails Due to Validation

A

aljodo

ASP.Net v1.1 & vb.net

Hi all,

I have a simple survey form with first name/last name text boxes at the
top. I have validators on these text boxes to ensure that something is
entered in them.

The form has a Submit button (asp:button) at the bottom and if the
validation has failed I want the form to return to the top, so that the
validation messages can be seen.

Could anyone please give me a code example of how to handle this?

I have tried using the click event in the code-behind page, but it
doesn't fire and I have tried putting an onclick event in the html code
e.g. <asp:button onclick="cmdSubmit_click"...> with the cmdSubmit_click
script setting focus to the first textbox, bt this gives me an error
when I try to run it:
BC30390: 'OfficeUsageSurvey._Default.Private Sub cmdSubmit_Click(sender
As Object, e As System.EventArgs)' is not accessible in this context
because it is 'Private'.

TIA for any help/advice.

Alan.
 
J

John Mardera

try using button.Attributes.Add("onclick", "javascript: callFunction();
return false;");
 
A

aljodo

Thanks for that John.
I'm a bit of a newbie to this, does it just go in the page_load event
and what does it then allow me to do?

Thanks again.
 
P

Peter Blum

Hi Alan,

The Microsoft validator controls cannot do this. I rewrote ASP.NET
validation to give it the features everyone has requested, including
solutions for this. My solution is called Professional Validation And More:
http://www.peterblum.com/vam/home.aspx.

You can set a property to have it set focus back to the first field with an
error when the submit button is clicked.
You can set a property to do the same when the user edits a field and its
incorrect.
My enhanced ValidationSummary control can offer hyperlinks on each error
message that when clicked, puts focus on the field associated with the
error.
My ValidationSummary has an option to scroll itself into view when you click
Submit.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top