Clearing Text In Regular Expression Validator

Last post 03-03-2009 12:50 AM by Radiant. 7 replies.

Sort Posts:

  • Clearing Text In Regular Expression Validator

    05-07-2004, 12:02 PM
    • Member
      120 point Member
    • nnaik
    • Member since 04-22-2004, 4:47 PM
    • Posts 24
    Dear all,


    How can I clear the text property of a Regular Expression Validator (or reset the controlto default state) from a client side button click ?

    I know I can use the My.Validator.InnerHTML property from a javascript file, but once I clear it using this property, the control stops working !!!

    Any help will be much appreciated.

    Thank you.

    Nandan
  • Re: Clearing Text In Regular Expression Validator

    05-07-2004, 2:06 PM
    • All-Star
      30,305 point All-Star
    • PLBlum
    • Member since 06-28-2002, 1:20 PM
    • Boston, MA
    • Posts 5,344
    • TrustedFriends-MVPs
    Validators keep their error message in the innerHTML full time. They simply show and hide themselves to work with the error message. To hide a validator, retrieve the object associated with its ClientID and set its visibility to 'hidden'.

    var vVal = document.all['clientid of validator'];
    vVal.style.visibility = "hidden";
    vVal.style.display = "none"; // ONLY if you are using Display="Dynamic"
    --- Peter Blum
    Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
    www.PeterBlum.com
  • Re: Clearing Text In Regular Expression Validator

    05-07-2004, 2:24 PM
    • Member
      120 point Member
    • nnaik
    • Member since 04-22-2004, 4:47 PM
    • Posts 24
    Thank you for your help.

    But doing what you asked me still has the same result. The control stops working after that point onwards, unless I explicitly make it visible through some more javascript code.

    All I need to do though is, just reset the control to its default setting... So, its still ready to validate anything being entered in the text box.

    Your help is appreciated.

    Nandan
  • Re: Clearing Text In Regular Expression Validator

    05-07-2004, 3:12 PM
    • All-Star
      30,305 point All-Star
    • PLBlum
    • Member since 06-28-2002, 1:20 PM
    • Boston, MA
    • Posts 5,344
    • TrustedFriends-MVPs
    Can you clarify how it stops working? I have been interpreting your message this way:
    You are trying to use the <form onreset= > event to clear validators to their hidden state. My answer gives you code that hides the validator without changing its innerHTML. When you changed the innerHTML, the validator would still show and hide the <span> tag containing it but have nothing inside the <span> tag to show. It appears off.

    FYI: If the reset button is the problem, here's an alternative solution to developing this custom code. The inability to clear validators upon reset is one of the many limitations of Microsoft's validators. I wrote a replacement to Microsoft's validators that overcomes its limitations including the ability to reset the validators to the same condition they were as the page first appeared. You can learn more about Professional Validation And More here and the limitations of Microsoft's validators here.
    --- Peter Blum
    Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
    www.PeterBlum.com
  • Re: Clearing Text In Regular Expression Validator

    05-10-2004, 7:05 AM
    • All-Star
      16,477 point All-Star
    • stiletto
    • Member since 07-10-2003, 8:42 AM
    • Louisville, KY
    • Posts 3,220
    If you call Page_Validate and the error has been fixed, then the error message should get cleared.

    Is this not what you are seeing?
  • Re: Clearing Text In Regular Expression Validator

    05-10-2004, 9:16 AM
    • Member
      120 point Member
    • nnaik
    • Member since 04-22-2004, 4:47 PM
    • Posts 24
    Dear Peter and Stiletto,
    Thank you for your replies...

    What is happening with my page is this:

    I have:

    A TextBox
    A "Clear" Button
    A Regular Expression Validator (Which lets the textbox accepts only Numbers)

    Everything works according to my expectations... Whenever a non-valid input is typed, an error message is correctly displayed...

    Now the problem arises when I want to clear the Input in the textbox and also the Error Message when the user presses the "clear" button.

    If I use InnerHTML property or the Visibility property explicitly to clear or hide the error message, the error message should be explicitly set or control needs to be explicitly displayed again at some later point, for it to continue working in a Normal fashion.

    All I need to know is this, if there is a way I can revert the control's state to the state it was in when the page was first loaded, then the error message should automatically get cleared with it... correct ? Or if there is any other simple way of clearing the error message WITHOUT tampering with the normal functioning of the control (like resetting the control to its default state)...

    Thank you for your help....

    Best regards,

    Nandan

  • Re: Clearing Text In Regular Expression Validator

    05-10-2004, 1:05 PM
    • All-Star
      30,305 point All-Star
    • PLBlum
    • Member since 06-28-2002, 1:20 PM
    • Boston, MA
    • Posts 5,344
    • TrustedFriends-MVPs
    You cannot modify the field to its original state and get the validator back to its hidden state. Validators only update on the onchange event of a field, which only fires if the user edits the field, and when the Page_Validate() function is run on submit.

    You haven't clearly said that your Clear button is a <input type='reset'> and you are using the <form onreset= > event or using the onclick event of an <input type='button'> with some script that you wrote to clear fields.

    Either way, if the fields are cleared, you can run the Page_Validate() function after you reset the fields. The side effect is if you have a RequiredFieldValidator, it will see any blank field and show its error message.

    As I said, this is a basic limitation of Microsoft's validators and I've offered you a commercial solution that handles this correctly. It's your choice whether you spend time developing hacks and lots of custom code each time you run into one of these limitations.
    --- Peter Blum
    Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
    www.PeterBlum.com
  • Re: Clearing Text In Regular Expression Validator

    03-03-2009, 12:50 AM
    • Member
      86 point Member
    • Radiant
    • Member since 10-18-2006, 4:03 AM
    • Posts 36

     

    Hi,

    I think this situation come across many programmers, I guess the solution can be obtained by using the following in javascript 

    document.getElementById("regurlarexpressionID").style.visibility = "hidden";

     

Page 1 of 1 (8 items)