Using C#
How to display a message box in C#
I cannot find the message box in the dropdownlist....
How to display a message box in webpages...
Using C#
How to display a message box in C#
I cannot find the message box in the dropdownlist....
How to display a message box in webpages...
Simply put there is no MessageBox Class in ASP.NET. Since ASP.NET executes on the server it would display on the server and not the clients machine (if there were one). Your best bet would be to use JavaScript or write your own.
Here's an example of creating your own MessageBox class for ASP.NET
public static class MessageBox
{
//StringBuilder to hold our client-side script
private static StringBuilder builder;
public static void Show(string message)
{
//initialize our StringBuilder
builder = new StringBuilder();
//format script by replacing characters with JavaScript compliant characters
message = message.Replace("\n", "\\n");
message = message.Replace("\"", "'");
//create our client-side script
builder.Append("<script language=\"");
builder.Append("javascript\"");
builder.Append("type=\"text/javascript\">");
builder.AppendFormat("\t\t");
builder.Append("alert( \"" + message + "\" );");
builder.Append(@"</script>");
//retrieve calling page
Page page = HttpContext.Current.Handler as Page;
//add client-side script to end of current response
page.Unload += new EventHandler(page_Unload);
}
private static void page_Unload(object sender, EventArgs e)
{
//write our script to the page at the end of the current response
HttpContext.Current.Response.Write(builder);
}
}
In a webpage, two ways to show a messagebox are to use a javascript alert
call or an AJAX (i.e. ASP.NET AJAX Control Toolkit) ModalPopupExtender
. The former is generally simpler and easier, but you won't have much control over it or be able to support proper interactivity.