RegularExpressionValidator.IsValid Returns TRUE!?

L

Larry Lawhead

My problem is that IsValid returns TRUE when, based on Validation
Expression, result should be FALSE.

Properties (departing from defaults):
Enable Client Script: False (Just incase it matters)
Validation Expression: [0-9\.,]*

Code Example:

private void cbxAvailable_CheckedChanged(object sender, System.EventArgs e)
{
if(valWeight.IsValid == false)
{
valWeight.ErrorMessage = "Use numbers only.";
tbxProdWeight.Text = "";
}
}

I created a prototype using the same property settings that works just fine.
Here is the code from that example:

private void Button2_Click(object sender, System.EventArgs e)
{
if(RegularExpressionValidator1.IsValid)
{
Label1.Text = TextBox1.Text;
TextBox1.Text = "";
}
else if (RegularExpressionValidator1.IsValid == false)
{
Label1.Text = "";
TextBox1.Text = "";
}
}

I must be overlooking something quit simple here. Any suggestions?

Thanks!
 
S

Sink

This usually happens when the control is being called
before the validate() function has been called for the
page and therefore your validator has been evaluated
as yet.

Try calling RegularExpressionValidator1.Validate()
before checking the IsValid property.
 
L

Larry Lawhead

Thanks, works great!

Sink said:
This usually happens when the control is being called
before the validate() function has been called for the
page and therefore your validator has been evaluated
as yet.

Try calling RegularExpressionValidator1.Validate()
before checking the IsValid property.
-----Original Message-----
My problem is that IsValid returns TRUE when, based on Validation
Expression, result should be FALSE.

Properties (departing from defaults):
Enable Client Script: False (Just incase it matters)
Validation Expression: [0-9\.,]*

Code Example:

private void cbxAvailable_CheckedChanged(object sender, System.EventArgs e)
{
if(valWeight.IsValid == false)
{
valWeight.ErrorMessage = "Use numbers only.";
tbxProdWeight.Text = "";
}
}

I created a prototype using the same property settings that works just fine.
Here is the code from that example:

private void Button2_Click(object sender, System.EventArgs e)
{
if(RegularExpressionValidator1.IsValid)
{
Label1.Text = TextBox1.Text;
TextBox1.Text = "";
}
else if (RegularExpressionValidator1.IsValid == false)
{
Label1.Text = "";
TextBox1.Text = "";
}
}

I must be overlooking something quit simple here. Any suggestions?

Thanks!


.
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top