Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have textbox and required field is for that .

on my button click i am checking wether my page is valid or not using page.isvalid()

how can i check the same using jquery for that button click
Posted
Comments
bbirajdar 14-Nov-13 3:49am    
If you use jQuery for validation, then it will be a client only validation. You should have a server side validation as well. So use asp.net validator controls

XML
<html>
<head>
<meta charset="utf-8">
<title>Makes "field" always required. Nothing and blanks are invalid.</title>
<link rel="stylesheet" href="http://jquery.bassistance.de/validate/demo/site-demos.css">
</head>
<body>
<form id="myform">
<label for="field">Required: </label>
<input type="text" class="left" id="field" name="field">
<br/>
<input type="submit" value="Validate!">
</form>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#myform" ).validate({
rules: {
field: {
required: true
}
}
});
</script>
</body>
</html>
 
Share this answer
 
On Button's OnClientClick Event, call one JavaScript function.
ASP.NET
<asp:Button OnClientClick="return validate()" runat="server"></asp:Button>

Inside that function, check if TextBox contains data or not by JavaScript document.getElementById() or jQuery $ selector.
JavaScript
function validate()
{
    var yourTextbox = document.getElementById("textBoxId");
 
    if(yourTextbox.value == null || yourTextbox.value == "")
    {
        return false;
    }
    else
    {
        return true;
    }
}
 
Share this answer
 
v3

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