Click here to Skip to main content
15,920,031 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want one example of how to validate asp.net textbox using javascript.
When I click the button,on clicking it first validate the text box after some action will be taken.
Posted

1 solution

javascript to validate login form

JavaScript
function Validation()
{
var userid=document.getElementById('<%=txtUserID.ClientID %>');
var pwd=document.getElementById('<%=txtPwd.ClientID %>');
if(userid.value=="")
{
alert("Please Enter UserID");
userid.focus();
return false;
}
if(pwd.value=="")
{
alert("Please Enter Password");
pwd.focus();
return false;
}
}



for button write the onclientclick in this way

ASP.NET
<asp:button id="btnLogin" runat="server" text="Submit" onclick="btnLogin_Click" onclientclick="javascript:return Validation();" xmlns:asp="#unknown" />
 
Share this answer
 
v2

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