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
Refer below sample.
Javascript
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" 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 BlankCheck(ele) { if (document.getElementById(ele.id).value == '') { document.getElementsByTagName('span')['0'].style.display = "block"; } } </script> </head> <body> <form id="form1" runat="server"> <div> <input name="txtName" type="text" id="txtName" onkeyup="BlankCheck(this);" /> <span class="Error" style="display: none; color: Red;">* Required!</span> </div> </form> </body> </html>
Demo
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() == '') { $('.Error').attr("style", "display:block;color: Red;"); } }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input name="txtName" type="text" id="txtName" /> <span class="Error" style="display: none; color: Red;">* Required!</span> </div> </form> </body> </html>
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.