locked
Validation Problem On WebuserControl ascx, When javascript modifies Child controls RRS feed

  • Question

  • User1275668648 posted

    [*-)] Weirdness:

    • I have a custom ascx control on a page.
    • I also have a requiredFieldValidator on the same page, validating it.
    • Specifically, the validator is validating a textbox in the ascx, using the syntax:
      ControlToValidate="MyControl:TextBox1"
    • The validator works fine UNTIL a bit a javascript, called by a child control of the ascx, changes the value of Textbox1 being validated. At that point, the Validator stops working completely.

     

    Not sure if this forum is the right place for ascx questions, but it's the only forum devoted to controls. Hope some expert can help!
     

    By the way, still no one has figured out an answer to my post, "How to stop WebUserControls overlapping each other"

    http://forums.asp.net/t/1250506.aspx 

    Wednesday, April 23, 2008 12:50 AM

Answers

  • User1275668648 posted

     Apparently, this behavior is inherent in the control.

    http://www.velocityreviews.com/forums/t110208-requiredfieldvalidator-allows-blank-values-when-initialvalue-is-set.html 


    I also found it's quite easy to write my own client-side validator, using the CustomValidator-

     

    1    <script type="text/javascript">
    2 function Validate(source, arguments)
    3 {
    4 arguments.IsValid =
    5 (
    6 arguments.Value != ''
    8 && arguments.Value!= '<%=TypingPrompt %>'
    10 );
    11 }
    12 </script>
    13
      

    Unfortunately, multiple instances on the same page seem to produce validation interference. i think they don't call their own validation script reliably, maybe due to their order of appearance in the rendered page?

    Fortunately, the TypingPrompt property is the same value for each of these controls on the page, so I lucked out.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 23, 2008 8:18 AM