Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Setting ValidationExpression clientSide

Setting ValidationExpression clientSide

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadmintoolsquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dwolver
    wrote on last edited by
    #1

    I have web page that I want to switch the validationExpression for control based on a checkBox. I'm trying the code in the script portion of the web page. When I submit the page and evaluate the Validation Control on the Page_Load during Postback the control has the same expression as defined in the .aspx file body, eg <asp:RegularExpressionValidator ID="EmailRegexValidator"   runat="server"    ControlToValidate="Email" ErrorMessage="Invalid Email"    ValidationExpression=".*@.{2,}\..{2,}"> ///// Does not seem to change in postback </asp:RegularExpressionValidator> Any ideas on what I need to do to make this work?       <script type="text/javascript" language="javascript">             function InitValidators()             {                   // retrieve instance of our checkbox                   var checkbox = document.getElementById('<%=enableValidatorsCheckBox.ClientID%>');                   // enable/disable all validators on page based on checkbox state                   ValidatorsEnabled(checkbox.checked);                              }             function ValidatorsEnabled(state)             {                   ValidatorEnable(document.getElementById('<%=NameRequiredFieldValidator.ClientID%>'), state);                   ValidatorEnable(document.getElementById('<%=EmailRequiredFieldValidator.ClientID%>'), state);                   ValidatorEnable(document.getElementById('<%=EmailRegexValidator.ClientID%>'), state);                   if (state)                      setValidation(".*@.{2,}\..{2,}")                   else &nbs

    N 1 Reply Last reply
    0
    • D dwolver

      I have web page that I want to switch the validationExpression for control based on a checkBox. I'm trying the code in the script portion of the web page. When I submit the page and evaluate the Validation Control on the Page_Load during Postback the control has the same expression as defined in the .aspx file body, eg <asp:RegularExpressionValidator ID="EmailRegexValidator"   runat="server"    ControlToValidate="Email" ErrorMessage="Invalid Email"    ValidationExpression=".*@.{2,}\..{2,}"> ///// Does not seem to change in postback </asp:RegularExpressionValidator> Any ideas on what I need to do to make this work?       <script type="text/javascript" language="javascript">             function InitValidators()             {                   // retrieve instance of our checkbox                   var checkbox = document.getElementById('<%=enableValidatorsCheckBox.ClientID%>');                   // enable/disable all validators on page based on checkbox state                   ValidatorsEnabled(checkbox.checked);                              }             function ValidatorsEnabled(state)             {                   ValidatorEnable(document.getElementById('<%=NameRequiredFieldValidator.ClientID%>'), state);                   ValidatorEnable(document.getElementById('<%=EmailRequiredFieldValidator.ClientID%>'), state);                   ValidatorEnable(document.getElementById('<%=EmailRegexValidator.ClientID%>'), state);                   if (state)                      setValidation(".*@.{2,}\..{2,}")                   else &nbs

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      dwolver wrote:

      document.getElementById("EmailRegexValidator").validationexpression = someVal;

      This won't work. ASP.NET processes validator controls on sever side and render HTML and JS to the response. Validator control may render as a span or div and there is no property called validationexpression for DIV or SPAN. Your best bet would be to use a custom validator. And use the regular expression methods provided in JS. :)

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups