简体   繁体   中英

How we can use Use Javascript and asp validation control together

i make a Aspx.page On a Single button Click event i want to call both Required Field Validator And My Java Script Function My problem is that Required Field Validator return False and next Java Script Function returns true then page is executed which is wrong i want to restrict first one (if this is false ) how can i do it.

<asp:Button ID="btnViewReport" runat="server" class="button" Text="<%$ Resources:Resource, btnViewReport %>" OnClick="btnViewReport_Click" ValidationGroup="g1" OnClientClick="return Jvalidate();" />

g1 is my validtion group for requied field validatoe

thanks in advance

shashank

You can write your javascript like this:

    function Jvalidate() {

        var r = document.getElementById("yourRequiredFieldValidatorID");

        if (r.style.visibility == "hidden") {
            //Do your Stuff
            //Return the state accordingly.
        }
        else {
            return false;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM