473,549 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using .NET Validation Controls

Tom
I know how to use these great controls. They work very
well. But is there a method or property I can use to set
the focus to the field that is in error.

For example... If I have a page with 5 text boxes on it
and they are all reaquired fields. When my user falis to
enter in something in field 3 and presses the Submit
button, the Summarty validation control fires just fine
but the focus is still on the Submit Button.

Is there a way to utilize the RequiredFieldVa lidator or
SummaryValidati onControl fields to set the focus to
txtField3?

Thanks

Tom

Nov 15 '05 #1
7 1796
Set the focus manually to the control yourself... like this:

// if userID (a TextBox) is not entered, or is invalid
// set the focus to it.
userID.Select() ;

Hope that helps,
-JG
Nov 15 '05 #2
Handle it in your submit button's click event....

"Tom" <an*******@disc ussions.microso ft.com> wrote in message
news:05******** *************** *****@phx.gbl.. .
I know how to use these great controls. They work very
well. But is there a method or property I can use to set
the focus to the field that is in error.

For example... If I have a page with 5 text boxes on it
and they are all reaquired fields. When my user falis to
enter in something in field 3 and presses the Submit
button, the Summarty validation control fires just fine
but the focus is still on the Submit Button.

Is there a way to utilize the RequiredFieldVa lidator or
SummaryValidati onControl fields to set the focus to
txtField3?

Thanks

Tom

Nov 15 '05 #3
Tom
That's the problem. The submit button does not fire if
their are validation errors.
-----Original Message-----
Handle it in your submit button's click event....

"Tom" <an*******@disc ussions.microso ft.com> wrote in messagenews:05******* *************** ******@phx.gbl. ..
I know how to use these great controls. They work very
well. But is there a method or property I can use to set the focus to the field that is in error.

For example... If I have a page with 5 text boxes on it
and they are all reaquired fields. When my user falis to enter in something in field 3 and presses the Submit
button, the Summarty validation control fires just fine
but the focus is still on the Submit Button.

Is there a way to utilize the RequiredFieldVa lidator or
SummaryValidati onControl fields to set the focus to
txtField3?

Thanks

Tom

.

Nov 15 '05 #4
Tom
The problem is where? The submit button event does not
fire. Its like the Validation controls are a pseudo
JavaScript, only without the bells and whistles.

I know how to set focus, I just don't know where to put
the code since the Submit Button's click event does not
fire.
Tom
-----Original Message-----
Set the focus manually to the control yourself... like this:
// if userID (a TextBox) is not entered, or is invalid
// set the focus to it.
userID.Select() ;

Hope that helps,
-JG
.

Nov 15 '05 #5
Don't the validators fire off events themselves?

doug

"Tom" <an*******@disc ussions.microso ft.com> wrote in message
news:04******** *************** *****@phx.gbl.. .
The problem is where? The submit button event does not
fire. Its like the Validation controls are a pseudo
JavaScript, only without the bells and whistles.

I know how to set focus, I just don't know where to put
the code since the Submit Button's click event does not
fire.
Tom
-----Original Message-----
Set the focus manually to the control yourself... like

this:

// if userID (a TextBox) is not entered, or is invalid
// set the focus to it.
userID.Select() ;

Hope that helps,
-JG
.

Nov 15 '05 #6
> The problem is where? The submit button event does not
fire. Its like the Validation controls are a pseudo
JavaScript, only without the bells and whistles.


Oh, my. I'm so sorry, I thought this was a question about validators and
controls on Winforms. My mistake.

Well, I looked around the docs on ASP.Net's validators and found no way of
doing it. You can do it with some javascript of your own, though (sample
..aspx page below). Just handle the onsubmit event of the form yourself
(ASP.Net will modify it so it calls it's validation routine first) and check
if your validators have their style.display properties set to "none". If
there is an error, this property will be moething other than "none" and you
then set the focus to the control.

Hope that helps,
-JG

<!-- Test.aspx -->

<%@ Page language="c#"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio 7.0">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "FlowLayout ">
<script language="javas cript">

function SetFocusOnError (theForm) {
if (emailValidator .style.display != "none" ||
validEmailValid ator.style.disp lay != "none") {
theForm.email.f ocus();
theForm.email.s elect();
return;
}
if (ageValidator.s tyle.display != "none" ||
overThirteenVal idator.style.di splay != "none") {
theForm.age.foc us();
theForm.age.sel ect();
return;
}
}

</script>

<form id="Test" method="post" runat="server"
onsubmit="SetFo cusOnError(this );">

<P>
Email: <asp:TextBox id="email" runat="server"> </asp:TextBox>

<asp:RequiredFi eldValidator id="emailValida tor" runat="server"
ErrorMessage="E nter your email." Display="Dynami c"
ControlToValida te="email"></asp:RequiredFie ldValidator>&nb sp;

<asp:RegularExp ressionValidato r id="validEmailV alidator" runat="server"
ErrorMessage="E nter a valid email address." Display="Dynami c"
ControlToValida te="email"
ValidationExpre ssion="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpr essionValidator > <BR>

Age:
<asp:TextBox id="age" runat="server"> </asp:TextBox>

<asp:RequiredFi eldValidator id="ageValidato r" runat="server"
ErrorMessage="E nter your age." Display="Dynami c"
ControlToValida te="age"></asp:RequiredFie ldValidator>&nb sp;

<asp:CompareVal idator id="overThirtee nValidator" runat="server"
ErrorMessage="M ust be older than 13." Display="Dynami c"
ControlToValida te="age" Type="Integer" ValueToCompare= "13"
Operator="Great erThan"></asp:CompareVali dator><BR>

<asp:Button id="Button1" runat="server" Text="Submit the form"
EnableViewState ="False" OnClick="Refres hMe"></asp:Button></P>

<p><asp:Label id="lblMsg" runat="server"> </asp:Label></p>
</form>
</body>
</HTML>

<script runat="server">
public void RefreshMe(objec t sender, EventArgs e) {
lblMsg.Text = "Submit accepted at: " +
DateTime.Now.To LongTimeString( );
}
</script>
Nov 15 '05 #7
Hello,

I think you should use the CustomValidator control, that control gives
you
the option to write your own Client-side and/or server side
validationcode.

Example:
You could write a generic javascript function which checks a field
for....whatever .

<script language="javas cript">
function ValidateField(s ource,arguments )
{

if(#do checks#)
{
arguments.isVal id = false; // Sets the Page.IsValid property
to true
source.focus();
}
else
{
arguments.isVal id = true;
}
}
</script>

- add a CustomValidator control to your form and set the following
properties:
- ControlToValida te = ControlToValida te (what a suprise)
- ClientValidatio nFunction = ValidateField
you should also write a serverside validation function in case the
users browser doesn't support javascript for some reason.

I haven't tried this myself, but i think it should work. I read in the
MSDN documentation this doesn't work for manditory checks because the
validation function doesn't fire when te control is empty, but you
could try it.

Good luck,

Eelco Duinsbergen

"Tom" <an*******@disc ussions.microso ft.com> wrote in message news:<04******* *************** ******@phx.gbl> ...
That's the problem. The submit button does not fire if
their are validation errors.
-----Original Message-----
Handle it in your submit button's click event....

"Tom" <an*******@disc ussions.microso ft.com> wrote in

message
news:05******* *************** ******@phx.gbl. ..
I know how to use these great controls. They work very
well. But is there a method or property I can use to set the focus to the field that is in error.

For example... If I have a page with 5 text boxes on it
and they are all reaquired fields. When my user falis to enter in something in field 3 and presses the Submit
button, the Summarty validation control fires just fine
but the focus is still on the Submit Button.

Is there a way to utilize the RequiredFieldVa lidator or
SummaryValidati onControl fields to set the focus to
txtField3?

Thanks

Tom

.

Nov 15 '05 #8

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

Similar topics

0
2264
by: Matthias Lohrer | last post by:
Hi, I'm playing around with the possibilities of Page.ParseControl. Thanks to Kirk Allen Evans I got my example running (Posting Juli, 17, "Re: Generating ASP.NET-Controls with XSLT possible?"). But looking deeper I run into a problem: Kirk said, that "validation works as expected", but in my experience it works only to a certain...
0
1393
by: Chris Nunciato | last post by:
I'm working on a simple Web application that uses a wizard-style data-entry paradigm (seven "pages", using "next" and "previous" buttons), and I'm having a problem with the validation. On page one (which is actually just a Panel control), when the user clicks "next," I hide Panel_1 and show Panel_2. However, the RequiredFieldValidator...
6
3693
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No confirmation message. By adding just an confirm attribute for 'onclick' event of the button doesn't work with validation controls. Is there any short way to...
4
2356
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there any get arounds for this problem apart from the traditional JavaScript?
7
10298
by: Paul | last post by:
Hi, I have a form where a user is required to enter a start date and an end date. Both are required and must between a specific date range (e.g. 01/01/1900 and 01/01/2099) and the end date cannot preceed the start date. How can I perform the necessary validation using the least number of validation controls. For example is it necessary that...
14
6275
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2) show the error message next to the control. For example, if the text field is empty with RequiredField Validator control, it can show the value in...
2
1131
by: NWx | last post by:
Hi, I have a form with few controls, few validation controls and a validation summary control I set-up appropriate Messages in Validations controls. However, if validation fails, I just want to display a * in validation control (or any other character), and instead display all validation messages in Validation summary control.
2
3985
by: Martyn Fewtrell | last post by:
Dear All I have a Windows 2003 Server with IIS6 where the validation controls on ASP.Net pages no longer work. I believe it to be specific to the server as if I create an ASP.Net page on the IIS Server of my Workstation (Win XP) with a text box, button and required field validator, this works fine. If I create the same page on the IIS6...
2
3711
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post all the messages to a message box (ShowMessageBox=true). The required field validation error messages show up in the summary just fine but I can't...
6
3273
by: Peter Afonin | last post by:
Hello, I'm creating an application in ASP.NET 1.1. I need to check whether at least one checkbox in my datagrid has been checked. To do this, I'm using Javascript - I'm adding this code to Page_Load event: Dim iCount As Int32 Dim sClientSideValidate As New StringBuilder iCount = dgReport.Items.Count For i As Int32 = 2 To iCount + 1
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.