I have a generic Alert function that display a message box in my asp.net app:
public void Alert(string sTitle, string sMessage)
{
StringBuilder sbScript = new StringBuilder();
sbScript.Append("<script language='Javascript'>");
sbScript.Append("var varDateNow = new Date();");
sbScript.Append("var varTimeNow = varDateNow.getTime();");
//sbScript.Append("var varAlertTime = document.getElementById('Master_cphAlertTime').value;");
sbScript.Append("var varAlertTime = document.getElementById('cphAlertTime').value;");
sbScript.Append("if(varTimeNow - varAlertTime < 1500)");
sbScript.Append("{alert('");
sbScript.Append(strMessage);
sbScript.Append("');}");
sbScript.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), strTitle, sbScript.ToString());
}
The Alert box does not appear every time. What is confusing me is why does it appear sometime and not appear at other times? The times when it does not appear is when a page is about to get redirected (or server.transfer) to another page.
Any ideas why the random functionality?
you can implement this static class in your application
and the call the allert/message box with just a simple call like this
MessageBox.Show("hello");