custom validator causing postback after error message is displayed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cameokid
    New Member
    • Feb 2008
    • 10

    custom validator causing postback after error message is displayed

    Hi,

    I have a table with some form fields. This table is hidden on load. I display it on click of a button.

    After i enter values and click button inside this table. It displays the custom validation error inside table (I want the error msg to be displayed inside table) but causes postback and hides the table. How do I stop the postback and display the error message while the table is visible.

    The code inside custom validation function is ...
    Code:
    if (conditon) {
    args.IsValid = false;
    }
    else {
    args.IsValid = true;
    }
    Last edited by Frinavale; Feb 11 '09, 03:40 PM. Reason: Moved to ASP.NET Answers and added [code] tags
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Set the style of the server in the button click event to display the table if there is an error.

    Code:
    if (conditon) {
        args.IsValid = false;
     //I'm assuming something didn't validate in this block
     //here you want to set the style of the table to make sure that it's displayed
     //if you aren't using style to hide the table, then make sure that the table
     //is visible in this block.
    }
    else {
        args.IsValid = true;
    }
    Although validating data on the server is always good practice, have you considered using a Client Side Validator Control to help make sure the data is valid before it's sent to the server?

    Comment

    • cameokid
      New Member
      • Feb 2008
      • 10

      #3
      Hey thanks.

      Sorry for the late reply.

      That is what i had to do. Used "clientValidati onFunction" property. Read somewhere on net that all validators do not cause post back except a custom validator. Hence i tried client validation using Javascript to avoid post back and it worked fine. Below is the JS Function.
      Code:
      function CustomVal_ClientValidate1(source, args)
          {
              var pcdata = document.getElementById("pinCodeTxt").value;
      
              if (pcdata.match(/\d{6}/))
              {
                  args.IsValid = true;
              }
              else
              {
                  args.IsValid = false;
              }
      
          }
      Last edited by Frinavale; Mar 16 '09, 01:02 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

      Comment

      Working...