views:

198

answers:

3

work on Asp.net C# vs05.My form has a button .Under this button event i save value on database.I want after the value save use get an alert message.How to show alert message

+1  A: 

RegisterClientScriptBlock could help?

http://msdn.microsoft.com/en-us/library/bahh2fef.aspx

Mark Redman
This could be used in addition to a jQuery UI Dialog. see http://jqueryui.com/demos/dialog/
Mark Redman
A: 

Add the WebMsgBox class below to your project. Then wherever you need to pop a message box from code just do this:

WebMsgBox.Show("How to show alert message!");

The WebMsgBox class:

using System;
using System.Text;
using System.Collections;
using System.Web;
using System.Web.UI;

public class WebMsgBox
{
  protected static Hashtable handlerPages = new Hashtable();

  private WebMsgBox() { }

  public static void Show(string Message)
  {
     if (!(handlerPages.Contains(HttpContext.Current.Handler)))
     {
        Page currentPage = (Page)HttpContext.Current.Handler;
        if (!((currentPage == null)))
        {
           Queue messageQueue = new Queue();
           messageQueue.Enqueue(Message);
           handlerPages.Add(HttpContext.Current.Handler, messageQueue);
           currentPage.Unload += new EventHandler(CurrentPageUnload);
        }
     }
     else
     {
        Queue queue = ((Queue)(handlerPages[HttpContext.Current.Handler]));
        queue.Enqueue(Message);
     }
  }

  private static void CurrentPageUnload(object sender, EventArgs e)
  {
     Queue queue = ((Queue)(handlerPages[HttpContext.Current.Handler]));
     if (queue != null)
     {
        StringBuilder builder = new StringBuilder();
        int iMsgCount = queue.Count;
        builder.Append("<script language='javascript'>");
        string sMsg;
        while ((iMsgCount > 0))
        {
           iMsgCount = iMsgCount - 1;
           sMsg = System.Convert.ToString(queue.Dequeue());
           sMsg = sMsg.Replace("\"", "'");
           builder.Append("alert( \"" + sMsg + "\" );");
        }
        builder.Append("</script>");
        handlerPages.Remove(HttpContext.Current.Handler);
        HttpContext.Current.Response.Write(builder.ToString());
     }
  }
}
David Glass
A: 

nice code.........

sdfsdfds