Groups | Blog | Home
all groups > asp.net > august 2003 >

asp.net : Dynamically changing the regular expression of Regular Expression validator


VSK
8/23/2003 10:59:57 PM
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










VSK
8/24/2003 10:47:34 AM
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

[quoted text, click to view]

Justin Dutoit
8/24/2003 3:59:08 PM
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
[quoted text, click to view]
What is the error?

hth
Justin Dutoit

[quoted text, click to view]

AddThis Social Bookmark Button