人们在创建消息框时会遇到很多问题,例如在asp.net的桌面应用程序中,有很多调用javascript警报的方法,但是在这里,我将解释如何在asp.net中生成消息框。
为此,请创建一个类,并在App_Code中将其命名为Messages.cs。 该类将具有一个生成消息框的方法,如下所示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
/// <summary>
/// Summary description for Messages
/// </summary>
public class Messages
{
public Messages()
{
//
// TODO: Add constructor logic here
//
}
public void CreateMessageAlert(string strMessage)
{
Guid guidKey = Guid.NewGuid();
Page pg = (Page)HttpContext.Current.Handler;
string strScript = "alert('" + strMessage + "');";
pg.ClientScript.RegisterStartupScript(pg.GetType(), guidKey.ToString(), strScript, true);
}
}
现在在您要显示“确定”消息框的页面中,您可以像这样调用
Messages myMsg=new Messages(); // create the object
myMsg.CreateMessageAlert("Your Message Here");
...
阿丹
From: https://bytes.com/topic/asp-net/insights/942116-how-create-message-box-asp-net