Hello, I have came across a Class file, changed it a bit to work for me, This method is very easy and works everywhere, IE, Chrome and Firefox others I have not tested.
Just add this Class File to Your Project
using System;
using System.Collections;
using System.ComponentModel;
using System.Text;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MessageAnkit
{
public class MessageBox
{
private static Hashtable m_executingPages = new Hashtable();
public static void Show(string sMessage)
{
if (!m_executingPages.Contains(HttpContext.Current.Handler))
{
Page executingPage = HttpContext.Current.Handler as Page;
if (executingPage != null)
{
Queue messageQueue = new Queue();
messageQueue.Enqueue(sMessage);
m_executingPages.Add(HttpContext.Current.Handler, messageQueue);
executingPage.Unload += new EventHandler(ExecutingPage_Unload);
}
}
else
{
Queue queue = (Queue)m_executingPages[HttpContext.Current.Handler];
queue.Enqueue(sMessage);
}
}
private static void ExecutingPage_Unload(object sender, EventArgs e)
{
Queue queue = (Queue)m_executingPages[HttpContext.Current.Handler];
if (queue != null)
{
StringBuilder sb = new StringBuilder();
int iMsgCount = queue.Count;
sb.Append("<script language='javascript'>");
string sMsg;
while (iMsgCount-- > 0)
{
sMsg = (string)queue.Dequeue();
sMsg = sMsg.Replace("\n", "\\n");
sMsg = sMsg.Replace("\"", "'");
sb.Append(@"alert( """ + sMsg + @""" );");
}
sb.Append(@"</" + "script>");
m_executingPages.Remove(HttpContext.Current.Handler);
HttpContext.Current.Response.Write(sb.ToString());
}
}
}
}
After that Just Add this line to display a Message
MessageAnkit.MessageBox.Show("Message String goes here");
I think this helps.
Happy Coding ... :)
Ankit Roy