Dear Team,
how to set blank and input validation in asp.net 4.0 using javascript
on change event, clickevent or which bet for client and server side
Hi pratikshir,
Refer the below sample.
Using JavaScript
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function BlankCheck(ele) { if (document.getElementById(ele.id).value == '') { alert('Name can\'t be blank'); } } </script> </head> <body> <form id="form1" runat="server"> <div> <input name="txtName" type="text" id="txtName" onkeyup="BlankCheck(this);" /> </div> </form> </body> </html>
Demo
Using jQuery
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(function () { $('#txtName').on('keyup', function () { if ($(this).val() == '') { alert('Name can\'t be blank'); } }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input name="txtName" type="text" id="txtName" /> </div> </form> </body> </html>
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.