Saturday, August 13, 2011

How to show client side message from server side code?

After saving or updating data successfully to database we can show users a client side confirmation message so that they can be sure about the result of their action. To achieve this  write ShowMessage method on your base page.

 public static void ShowMessage(string message, Page page)
    {
        message = message.Replace("'""\'");
        string script = "<script language=\"javascript\"  type=\"text/javascript\">alert('" + message + "');</script>";
        ScriptManager.RegisterStartupScript(page, page.GetType(), "AlertMessage", script, false);
    }

Call this method after saving or updating data to database. In the following code snippet I have just shown how to call this method in your page:


                   Int32 Id = 0;

                    Id = oHrEmployeeFamilyMemberBLL.HrEmployeeFamilyMember_Add(entity);
                    if (Id > 0)
                    {
                        Alert.ShowMessage("Record has been saved successfully",this);
                    }




No comments:

Post a Comment