RegularExpressionValidator Added Dynamically giving JavaScript error

Last post 11-17-2006 5:33 AM by Jasson_King. 3 replies.

Sort Posts:

  • RegularExpressionValidator Added Dynamically giving JavaScript error

    11-10-2006, 5:11 AM
    • Member
      329 point Member
    • jmedia
    • Member since 03-26-2004, 8:47 AM
    • Manchester, UK
    • Posts 86

    I have a datagrid to which I am dynamically adding a textbox and then a regularexpressionvalidator, however when the page loads i get a javscipt error on the line of code generated by the framework (See below)

    e.Item.Cells[3].Controls.Add(AddNewPayRate(js, pr));
    e.Item.Cells[3].Controls.Add(AddRegEx((TextBox)e.Item.Cells[3].Controls[0]));
    
    private RegularExpressionValidator AddRegEx(TextBox txt)
    {
            RegularExpressionValidator reg = new RegularExpressionValidator();
            reg.ControlToValidate = txt.ID;
            reg.ErrorMessage = "Pay Rate must be numeric";
            reg.ValidationExpression = @"^[0-9\.]+$";
            reg.Display = ValidatorDisplay.None;
            return reg;
    }
    
    Then the error is flagged up on the following line of code when the page is loaded:
     
    <script type="text/javascript">
    <!--
    var Page_ValidationSummaries =  new Array(document.getElementById("vldSummary"));
    var Page_Validators =  new Array(document.getElementById("summaryDG_js4-5-7_ctl00"), document.getElementById("summaryDG_js17-5-7_ctl00"), document.getElementById("summaryDG_js13-5-7_ctl00"));
    // -->
    </script>
     
    Any help would be most appreciated
    It's all fun and games until someone loses an eye, then it's just fun and games you can't see.
  • Re: RegularExpressionValidator Added Dynamically giving JavaScript error

    11-17-2006, 4:32 AM

    Hi,

       Can you post the javascript error message here ?
     

  • Re: RegularExpressionValidator Added Dynamically giving JavaScript error

    11-17-2006, 4:37 AM
    • Member
      329 point Member
    • jmedia
    • Member since 03-26-2004, 8:47 AM
    • Manchester, UK
    • Posts 86
    I've managed to work out what the issue was, it was because I was using the - in the naming of the control and it was this that was causing the issue with Javascript
    It's all fun and games until someone loses an eye, then it's just fun and games you can't see.
  • Re: RegularExpressionValidator Added Dynamically giving JavaScript error

    11-17-2006, 5:33 AM
    Answer
    If we want to pass ID of a control to javascript,we should use Control.ClientID.Otherwise we will get javascript error in the client side. 
Page 1 of 1 (4 items)