How to make a alert box on Button click
-
try: response.write("alert('Hello!');") Sheel Gohe
-
try: response.write("alert('Hello!');") Sheel Gohe
-
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 functionHope this helps you... :)