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>
dharmendr says: Hi pratikshir, Refer the below sample. Using JavaScript 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <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> Demo
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
head
runat
"server"
title
></
script
type
"text/javascript"
function BlankCheck(ele) {
if (document.getElementById(ele.id).value == '') {
alert('Name can\'t be blank');
}
</
body
form
id
"form1"
div
input
name
"txtName"
"text"
onkeyup
"BlankCheck(this);"
/>
src
"https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
$(function () {
$('#txtName').on('keyup', function () {
if ($(this).val() == '') {
});
How to highlight or error message near by control
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>
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>
thanks for you suggetion....
but not working in script managenr also update panel
and how to check on button click event...
You can't ask multiple queries within a question. This is against forum rules and necessary to maintain clean forum. It is requested Mark Answer the replies when question is answered and ask a new question as a responsible member to help fellow programmers around the world.
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.