Hi, On click of the button call a javascript method in code behind, Below is .aspx.cs page code: For eg : Let server control button id be 'btnSave'
btnSave.Attributes.Add("OnClick","javascript:return ValidateTextBox();");
.aspx page code :
function ValidateTextBox()
{
//for eg:let the textbox id be 'txtName'
//First check whether the textbox exists
if(document.getElementById("txtName")!=null)
{
if(isEmptyCheck("txtName")==true)
{
alert("Text box value is empty,please enter value");
return false;
}
}
}
//function to check whether text box value is empty or not
function isEmptyCheck(X)
{
if((document.forms[0].elements[X].value=="") || (document.forms[0].elements[X].value.substring(0,1) == ' '))
{
return true;
}
return false;
}//end of function
Hope this helps you... :)