Dynamically changing the regular expression of Regular Expression validator

V

VSK

Hi all,

I have a .ascx file with

dropdownbox (SSN, EmpName)
textbox
submit button
regular expression validator( controltovalidate is the above textbox)

Now i want to change the Regular Expression of the validator based on the
dropdownlist item selected.
So i have written the following code in .ascx.cs file

private void ValidateSearchText()
{

if(drpSearchField.SelectedItem.Text == "EmpName")

{

genericRegExpression.ValidationExpression = @"^[A-Za-z\-]+$";

genericRegExpression.ErrorMessage="Please enter only characters for
LastName" ;

}else{

...........................

}

}

This method will be called when the button is clicked.

The problem is that the validator is emitting error mesaage as expected.

Has anyone tried this. Please suggest on this.

Thanks

VSK
 
J

Justin Dutoit

More experienced folks could hlp you more on this, but
I'd say try dynamically creating the RegularExpressionValidator, and add it
to the Controls collection.

What do you mean
The problem is that the validator is emitting error mesaage as expected.
What is the error?

hth
Justin Dutoit

VSK said:
Hi all,

I have a .ascx file with

dropdownbox (SSN, EmpName)
textbox
submit button
regular expression validator( controltovalidate is the above textbox)

Now i want to change the Regular Expression of the validator based on the
dropdownlist item selected.
So i have written the following code in .ascx.cs file

private void ValidateSearchText()
{

if(drpSearchField.SelectedItem.Text == "EmpName")

{

genericRegExpression.ValidationExpression = @"^[A-Za-z\-]+$";

genericRegExpression.ErrorMessage="Please enter only characters for
LastName" ;

}else{

...........................

}

}

This method will be called when the button is clicked.

The problem is that the validator is emitting error mesaage as expected.

Has anyone tried this. Please suggest on this.

Thanks

VSK
 
V

VSK

sorry abt that...

what i actually meant was it was not showing Error message.(The problem is
that the validator is NOT emitting error mesaage as expected.)

but now i got it working...

thanks for help....

--VSK

Justin Dutoit said:
More experienced folks could hlp you more on this, but
I'd say try dynamically creating the RegularExpressionValidator, and add it
to the Controls collection.

What do you mean
The problem is that the validator is emitting error mesaage as expected.
What is the error?

hth
Justin Dutoit

VSK said:
Hi all,

I have a .ascx file with

dropdownbox (SSN, EmpName)
textbox
submit button
regular expression validator( controltovalidate is the above textbox)

Now i want to change the Regular Expression of the validator based on the
dropdownlist item selected.
So i have written the following code in .ascx.cs file

private void ValidateSearchText()
{

if(drpSearchField.SelectedItem.Text == "EmpName")

{

genericRegExpression.ValidationExpression = @"^[A-Za-z\-]+$";

genericRegExpression.ErrorMessage="Please enter only characters for
LastName" ;

}else{

...........................

}

}

This method will be called when the button is clicked.

The problem is that the validator is emitting error mesaage as expected.

Has anyone tried this. Please suggest on this.

Thanks

VSK
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top