Validation

S

Shelly

I have learned a bit about validation controls (and they are nice). Here is
my question:

Suppose you have a group of checkboxes and want to validate that at least
one of them is checked. Is there a control for that?

What about that at least one of a group of text boxes has an entry and that
it is a number within a particular range?

Shelly
 
S

Shelly

Steve C. Orr said:
I believe that's where custom validators come into play.

Here's more info:
http://SteveOrr.net/articles/Validation.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

Thank you. I am sure it will help. That was one of the most clearly
written and easy to understand articles I have read (as a beginner at .NET).
I only have one question about the article and it has to do with
ValidationSummary. With that control, how does it know what the other
validations are to present the summary? Is it automatic? Do you have to
surround all the others with this validation control? The way I handled a
page with many errors was to move all the validations to top of the page,
put them in red, and make them all dynamic. I did this because having them
static caused the error messages to overrun other controls and that was
downright ugly. Of course, moving them there meant that I couldn't use the
Text property to put an asterisk for required (something I didn't know until
I read your article), but that can be accomplished by putting it in the
label describing the control.
 
M

Mark Rae [MVP]

I have learned a bit about validation controls (and they are nice). Here
is my question:

Validation controls are extremely easy to use but I find them very
restricting, which is why I never go anywhere near them... I always roll my
own client-side JavaScript validation every time...
Suppose you have a group of checkboxes and want to validate that at least
one of them is checked. Is there a control for that?
What about that at least one of a group of text boxes has an entry and
that it is a number within a particular range?

<script text="text/javascript">
function validateForm()
{
if (!document.getElementById('<%=myCheckBox1.ClientID%>').checked &&
!document.getElementById('<%=myCheckBox2.ClientID%>').checked &&
!document.getElementById('<%=myCheckBox3.ClientID%>').checked
&&)
{
alert('At least one of the checkboxes must be checked');
return false;
}
if (document.getElementById('<%=myTextBox1.ClientID%>').value.length
== 0 &&
document.getElementById('<%=myTextBox2.ClientID%>').value.length
== 0 &&
document.getElementById('<%=myTextBox3.ClientID%>').value.length
== 0 &&
{
alert('At least one of the textboxes must contain data');
return false;
}
if (document.getElementById(' said:
{
if
(!isNumeric(document.getElementById('<%=myTextBox1.ClientID%>').value)
{
alert('Textbox1 does not contain a valid number');
return false;
}
if
(parseInt(document.getElementById('<%=myTextBox1.ClientID%>').value) <= 0)
{
alert('Textbox1 must contain a valid number greater than
zero');
return false;
}
}
}
</script>

<asp:Button ID="MyButton" runat="server" OnClick="MyButton_Click"
OnClientClick="return validateForm();" />
 
S

Shelly

Steve C. Orr said:
I believe that's where custom validators come into play.

Here's more info:
http://SteveOrr.net/articles/Validation.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

I tried this and have some questions:

1 - When I went to put in the control to validate, it only offered text
boxes. The check boxes were not offered, nor was the button for submittal.
2 - There was a ClientValidationFunction in the properties but no
ServerValidationFunction. (I wound up spinning one of my own as in your
article),
 

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

Top