Sunday, October 20, 2013

Validate ASP.Net Text Box Control Using Jquery for Blank Value

1 comment
In this tutorial  let us find out how to validate text box control  in  .net for blank value. If the text box value is null or empty then alert would be displayed to the user to enter value in text box.

In some of other posts related to jquery we discussed about: Jquery to validate file size of file upload control, Jquery to get Length of String

Jquery to Validate ASP.Net Text Box for Null or Empty value
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {


            $('#btnsubmit').click(function () {

                var uname = $('#txtname').val();
                if (uname == '')
                {
                    alert("Please Enter Name");
                }

            });
        });


    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox runat="server" ID="txtname"></asp:TextBox>
            <asp:Button ID="btnsubmit" runat="server" Text="Submit"  />
        </div>
    </form>
</body>

</html>

1 comment: