z zx

z zx

  • NA
  • 6
  • 0

how to return a value after user show("message") in asp.net??

Dec 10 2008 12:37 AM
hi all
 
but I want to return "yes" or "no" when I use show("message")
how can i DO this? can you help me to change this class to return "yes" or "no" after use  show("message")?
string stra =show("message")
 
how to change this class ,if I want to do this  string stra =show("message")  .return yes or no  in webform?
 
 
the code :

using System; using Microsoft.VisualBasic; using System.Text; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace TestWebMsgApp { 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()); } } } }