Search code examples
c#messagebox

MessageBox in C# showing error


I was attempting to add MessageBox.Show(Message); and it was not found in my C# .net web application (button click method and also in Page_Load).An error showing like

'The name 'MessageBox' does not exist in the current context'

Do I need to add any assembly reference for this? (I am using .net framework 4). Is there any alternative method for this?


Solution

  • Use This:

    System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('" + Message + "')", true);
    

    Hope This help.