gpt4 book ai didi

c# - 如何在 asp.net 上显示 MessageBox?

转载 作者:太空狗 更新时间:2023-10-29 18:11:22 25 4
gpt4 key购买 nike

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

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

但它不起作用。

最佳答案

MessageBox 在 ASP.NET 中不存在。如果您需要浏览器中的功能,例如显示消息框,则需要选择 javascript。 ASP.NET 为您提供了注入(inject) 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);
}

这个样本的 taken from MSDN .

关于c# - 如何在 asp.net 上显示 MessageBox?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4301770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com