Dynamically changing the regular expression of Regular Expression validator

Discussion in 'ASP .Net' started by VSK, Aug 24, 2003.

  1. VSK

    VSK Guest

    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, Aug 24, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    Justin Dutoit, Aug 24, 2003
    #2
    1. Advertising

  3. VSK

    VSK Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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, Aug 24, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Vallelunga
    Replies:
    2
    Views:
    8,261
    Brian Vallelunga
    Jul 31, 2003
  2. Bryce Budd

    Regular Expression Validator

    Bryce Budd, Sep 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    562
    Brian Davis
    Sep 18, 2003
  3. Simple Simon
    Replies:
    2
    Views:
    4,322
    Simple Simon
    Nov 4, 2003
  4. Edward
    Replies:
    0
    Views:
    817
    Edward
    Dec 4, 2003
  5. S.Kartikeyan
    Replies:
    1
    Views:
    1,910
    Martin Dechev
    Feb 24, 2004
Loading...

Share This Page