Display Success Popup Box after record inserted using C# and VB.Net in ASP.Net

Last Reply one month ago By dharmendr

Posted one month ago

hello,

i have many forms where on button click it saves data. 

i want when user click on save button if data add successfully it shows a popup message on top bar

please advice how to achieve it globally. 

i am using try catch block

You are viewing reply posted by: dharmendr one month ago.
Posted one month ago

Hi nauna,

Yes you can.

Follow the below steps.

1. Create a class file and write the below code.

public class MessagePopup
{
    private System.Web.UI.Page page;
    public MessagePopup(System.Web.UI.Page pages)
    {
        page = pages;
    }

    public void ShowMessage(string Message, string messageType)
    {
        if (messageType.ToLower() == "success")
        {
            messageType = "Success";
        }
        else if (messageType.ToLower() == "error")
        {
            messageType = "Error";
        }
        else if (messageType.ToLower() == "info")
        {
            messageType = "Info";
        }
        else if (messageType.ToLower() == "warning")
        {
            messageType = "Warning";
        }
        System.Web.UI.ScriptManager.RegisterStartupScript(page, this.GetType(), System.Guid.NewGuid().ToString(), "ShowMessage('" + Message + "','" + messageType + "');", true);
    }
}

2. Call the method using the below code in the page where you want to call.

MessagePopup messagePopup = new MessagePopup(this.Page);
messagePopup.ShowMessage("Record submitted successfully", "Success");