Showing posts with label Javascript validation in C#. Show all posts
Showing posts with label Javascript validation in C#. Show all posts

Wednesday, June 25, 2008

Javascript validation-ASP.NET

function Murugesan()
{
var d=document.getElementById('TextBox1').value;
if(d=="")
{
alert("cant be blank");
return false;
}
else
{
return true;
}

}
Place above source code on source code window between head tag.Here I simply check the TextBox,wheather it has value or blank.

On code behind file,
Register the control which has to be call this javascript.
Button1.Attributes.Add("onclick", "return Murugesan()");

Friday, June 06, 2008

Javascript Validation - ASP.NET

This simple explanation will help you to implement more and pop up logics to work out.

Go to design page of your page and place the script tag between head tag.

I wanted to check my text box had value or not.
I name it txtAmount and then validation starts here,

function CheckValues()
{
if(document.getElementById("<%=txtAmount.ClientID%>")=="")
{
alert("You forgot to mention your deposit amount!");
document.getElementById("<%=txtAmount.ClientID%>").focus();

return false;
}
return true;
}
}

Now I completed the Validation part,Now I need to register this validation accepted by the server,so go to Code behind file

Add this line on OnClick Events of the Button

Button1.attributes.Add("OnClick","return CheckValues()");