I used the above code to achieve the desired result
if (!String.IsNullOrEmpty(message.Trim()))
{
message = message.Replace("\\n", "\\\\n");
string script = "setTimeout(\"alert('" + message + "');\",0);";
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), script, true);
}
Call this method and pass the message string