Rev
Rev

Reputation: 2275

How to show notification or message from server-Side in asp.net?

As you can see I want to show to client some text which are most Important for Client's. so I plan to show Alert form server side . for implementing this I create JScript Function Like below Code:

 function ShowMessage(s) {
        alert(s);
 }

So in cs code write this method to call JS-Function:

public static void ShowMessage(System.Web.UI.Page Pointer, string Message)
{
    if (!Pointer.ClientScript.IsStartupScriptRegistered("message"))
        Pointer.Page.ClientScript.RegisterStartupScript
            (Pointer.Master.GetType(), "message", "ShowMessage('" + Message + "');", true);
}

This Code work well ;)

So I try to approve My web-app. and using Update-panel and Script-Manager. after using them I Got new Problem.(put all button in Update-Panel)

In each Button-Click or better say for each Post-back occur, If Call ShowMessage method -> Nothing happen. no message , no alert!!!

Question :

Upvotes: 1

Views: 5184

Answers (1)

yogi
yogi

Reputation: 19619

Try this

public static void ShowMessage(System.Web.UI.Page Pointer, string Message)
{
    if (!Pointer.ClientScript.IsStartupScriptRegistered("message"))
      ScriptManager.RegisterStartupScript(Pointer,
                                          Pointer.Master.GetType(),
                                          "message", 
                                          "ShowMessage('" + Message + "');", 
                                          true);
}

Since you are using update panels therefore that functionality didn't work which you were using previously without update panels because the page life cycle of your webpage changed after using that update panel control, Page.ClientScript woks only with traditional web page life cycle.

For more you may like to go here.

Upvotes: 1

Related Questions