Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to use onclientclick for both validation and alert message...
i want one button to validate textboxes and display alert message...how can i set both to only one button?
Posted

1 solution

Dear Friend,

Below Eg. you can refer, since it is javascript validation you cannot write in class file, you have to write in aspx file only.

XML
<asp:Button ID="btn_sub" runat="server" Text="SUBMIT" CssClass="btn" OnClick="btn_sub_Click" OnClientClick="javascript:return valid();" />

<script type="text/javascript">
        function valid() {
            var t1 = document.getElementById('text_box1').value;
            var t2 = document.getElementById('text_box2').value;
            if (t1 == "") {
                alert("Enter Text 1");
                return false;
            }
            else if (t2 == "") {
                alert("Enter Text 2");
                return false;
            }
            else {
                return true;
            }
        }
    </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900