Friday, March 8, 2013

Write Javascript alert message box in ASP.NET code behind


To Write Javascript alert message box function  in ASP.NET code behind refer the below code. Just pass the error message as parameter to this function by calling it.
public void ShowAlertMessage(string error)  
{  
     Page page = HttpContext.Current.Handler as Page;  
     if (page != null)  
     {  
          error = error.Replace("'", "\'");  
          ScriptManager.RegisterStartupScript(page, page.GetType(), "errmsg", "alert('" + error + "');", true);  
     }  
}