locked
ASP requiredfieldvalidator and Jquery RRS feed

  • Question

  • User-1305530094 posted

    I have a problem, I have some jquery plugins running on my page (i.e. tabs). when i add asp requiredfieldvalidator the jquery function stops working, any ideas?

    Saturday, February 25, 2017 4:00 AM

Answers

  • User2103319870 posted

    RequiredFieldValidator adds a Jquery reference by default. So if you have your jquery references in head section of page then the control wont work.  Reason is Jquery wont work will duplicate references. See the below image for more details

    Solution:

    Move the Jquery reference from Head section to end of page or after form tag like below

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1">
                </asp:RequiredFieldValidator>
                <input type='text' id='cal1' />
            </div>
        </form>
        <%--  Moved from head section to here--%>
        <link href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
        <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
        <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
        <script>
            $(document).ready(function () {
                $('#cal1').datepicker();
            });
        </script>
    </body>
    </html>

    Source URL

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 25, 2017 1:35 PM