Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show MessageBox on asp.net?

Tags:

c#

asp.net

if I need to show a MessageBox on my ASP.NET WebForm, how to do it?

I try: Messagebox.show("dd");

But it's not working.

like image 413
Gold Avatar asked Nov 29 '10 07:11

Gold


1 Answers

MessageBox doesn't exist in ASP.NET. If you need functionality in the browser, like showing a message box, then you need to opt for javascript. ASP.NET provides you with means to inject javascript which gets rendered and executed when the html sent to the browser's loaded and displayed. You can use the following code in the Page_Load for example:

Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
{
    String cstext = "alert('Hello World');";
    cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
}

This sample's taken from MSDN.

like image 150
Kris van der Mast Avatar answered Oct 06 '22 17:10

Kris van der Mast