şükela:  tümü | bugün soru sor
  • asp.net de normal yollarla çıkıralamadığı için java script yoluna gidilebilir

    aşağıda ki kodu bir class a yazı babalar gibi kullanabilirsiniz :

    tabi ilk system.collections ve system.text de de yukari iliştirilmeli

    protected static hashtable handlerpages = new hashtable();

    private message()
    {
    }

    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)
    {
    string builder builder = new system.text.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());
    }
    }

    ardından class imini proıgramınza yazıp kullanabilirsiniz