JS validation doesnt work when NET build-in validators are used

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default JS validation doesnt work when NET build-in validators are used

    I am frustrated by the issue, and looking for a workaround.

    I have a dropdown list, and a button and some other controls on the page.
    When the button is clicked, I need to ensure a valid dropdown list item is
    selected, (e.g. selectedIndex > 0, as the 1st item in ddl is dummy record).
    Also, I need use some NET build-in validators for other controls.

    What I did is:

    - Create a JS function
    function submitForm() {
    if ( (document.getElementById("ddl").selectedIndex <= 0)) {
    alert("nothing selected in ddl");
    return false;
    }

    if (typeof(Page_ClientValidate) == 'function')
    Page_ClientValidate();

    if (Page_IsValid){
    ValidatorOnSubmit();//this will fire postback
    }
    }

    - on the server side add attributes to button.
    btnSubmit.Attributes.add("onClick","submitForm()")


    I wonder if anyone can help me out. Thanks.





    Sean Guest

  2. Similar Questions and Discussions

    1. Validators and Page validation
      My page is not receiving any validators that I have added to the page during PageIndexChanged event. If I call the same piece of code from some...
    2. postback doesn't work with validators.!
      I have a strange problem.. once I put any validators on my form, say a simple RequiredFieldValidator, then there is no postback happening. Even...
    3. test and masking movements ok in build mode in fla doesnt work
      This use to work on flash 6, but in mx 2004 trial. it doesnt does it work in real 2004 ? Also how is using apple for flash different from pc, going...
    4. #25955 [Opn]: MacOS 10.3 (Panther) doesnt build php. Fails on resolver stuff
      ID: 25955 User updated by: andreas at fink dot org Reported By: andreas at fink dot org Status: Open Bug Type: ...
    5. validation summary doesnt display when there's client-side validation
      I have a custom validator that validates a numeric field, txtField, that allows for thousand separators. I also placed a validation summary so...
  3. #2

    Default Re: JS validation doesnt work when NET build-in validators are used

    Sean,

    Use the required field validator instead of the javascript you wrote. The
    required field validator has a property, "InitialValue", set that property
    equal to the initial text in your dropdown and that will solve your problem.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche
    "Sean" <ssmith@yahoo.com> wrote in message
    news:eoWy$t3WDHA.384@TK2MSFTNGP12.phx.gbl...
    > I am frustrated by the issue, and looking for a workaround.
    >
    > I have a dropdown list, and a button and some other controls on the page.
    > When the button is clicked, I need to ensure a valid dropdown list item is
    > selected, (e.g. selectedIndex > 0, as the 1st item in ddl is dummy
    record).
    > Also, I need use some NET build-in validators for other controls.
    >
    > What I did is:
    >
    > - Create a JS function
    > function submitForm() {
    > if ( (document.getElementById("ddl").selectedIndex <= 0)) {
    > alert("nothing selected in ddl");
    > return false;
    > }
    >
    > if (typeof(Page_ClientValidate) == 'function')
    > Page_ClientValidate();
    >
    > if (Page_IsValid){
    > ValidatorOnSubmit();//this will fire postback
    > }
    > }
    >
    > - on the server side add attributes to button.
    > btnSubmit.Attributes.add("onClick","submitForm()")
    >
    >
    > I wonder if anyone can help me out. Thanks.
    >
    >
    >
    >
    >

    S. Justin Gengo Guest

  4. #3

    Default Re: JS validation doesnt work when NET build-in validators are used

    There's a detailed discussion by Mike Moore on this issue:

    [url]http://www.aspalliance.com/kenc/faq6.aspx[/url]


    "Sean" <ssmith@yahoo.com> wrote in message
    news:eoWy$t3WDHA.384@TK2MSFTNGP12.phx.gbl...
    I am frustrated by the issue, and looking for a workaround.

    I have a dropdown list, and a button and some other controls on the page.
    When the button is clicked, I need to ensure a valid dropdown list item is
    selected, (e.g. selectedIndex > 0, as the 1st item in ddl is dummy record).
    Also, I need use some NET build-in validators for other controls.

    What I did is:

    - Create a JS function
    function submitForm() {
    if ( (document.getElementById("ddl").selectedIndex <= 0)) {
    alert("nothing selected in ddl");
    return false;
    }

    if (typeof(Page_ClientValidate) == 'function')
    Page_ClientValidate();

    if (Page_IsValid){
    ValidatorOnSubmit();//this will fire postback
    }
    }

    - on the server side add attributes to button.
    btnSubmit.Attributes.add("onClick","submitForm()")


    I wonder if anyone can help me out. Thanks.






    Ken Cox [Microsoft MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139