如何在asp.net上显示MessageBox?

Gol*_*old 8 c# asp.net

如果我需要在我的ASP.NET WebForm上显示MessageBox,该怎么做?

我尝试: Messagebox.show("dd");

但它不起作用.

Kri*_*ast 11

ASP.NET中不存在MessageBox.如果您需要在浏览器中使用功能,例如显示消息框,那么您需要选择javascript.ASP.NET为您提供了注入javascript的方法,当发送到浏览器的html被加载和显示时,javascript将被呈现和执行.例如,您可以在Page_Load中使用以下代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

此示例取自MSDN.


Vad*_*dim 5

有简洁明了的方法:

Response.Write("<script>alert('Your text');</script>");
Run Code Online (Sandbox Code Playgroud)