青春须早为,岂能长少年。这篇文章主要讲述弹出消息对话框类相关的知识,希望能为你提供帮助。
using System.Text;
namespace DotNet.Utilities
//页面中弹出对话框
public class MessageBox
private MessageBox()
#region 显示消息提示对话框
/// <
summary>
/// 显示消息提示对话框
/// <
/summary>
/// <
param name="page">
当前页面指针,一般为this<
/param>
/// <
param name="msg">
提示信息<
/param>
public static void Show(System.Web.UI.Page page, string msg)
// page.RegisterStartupScript("message", "<
script language=javascript defer>
alert(" + msg.ToString() + ");
<
/script>
");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<
script language=javascript defer>
alert(" + msg.ToString() + ");
<
/script>
");
#endregion
#region 控件点击 消息确认提示框
/// <
summary>
/// 控件点击 消息确认提示框
/// <
/summary>
/// <
param name="page">
当前页面指针,一般为this<
/param>
/// <
param name="msg">
提示信息<
/param>
public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
//Control.Attributes.Add("onClick","if (!window.confirm("+msg+"))return false;
");
Control.Attributes.Add("onclick", "return confirm(" + msg + ");
");
#endregion
#region 显示消息提示对话框,并进行页面跳转
/// <
summary>
/// 显示消息提示对话框,并进行页面跳转
/// <
/summary>
/// <
param name="page">
当前页面指针,一般为this<
/param>
/// <
param name="msg">
提示信息<
/param>
/// <
param name="url">
跳转的目标URL<
/param>
public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
StringBuilder Builder = new StringBuilder();
Builder.Append("<
script language=javascript defer>
");
Builder.AppendFormat("alert(0);
", msg);
Builder.AppendFormat("location.href=https://www.songbingjia.com/android/0", url);
【弹出消息对话框类】Builder.Append("<
/script>
");
//page.RegisterStartupScript("message", Builder.ToString());
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url, bool top)
StringBuilder Builder = new StringBuilder();
Builder.Append("<
script language=javascript defer>
");
Builder.AppendFormat("alert(0);
", msg);
if (top == true)
Builder.AppendFormat("top.location.href=https://www.songbingjia.com/android/0", url);
else
Builder.AppendFormat("location.href=https://www.songbingjia.com/android/0", url);
Builder.Append("<
/script>
");
// page.RegisterStartupScript("message", Builder.ToString());
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
#endregion
#region 输出自定义脚本信息
/// <
summary>
/// 输出自定义脚本信息
/// <
/summary>
/// <
param name="page">
当前页面指针,一般为this<
/param>
/// <
param name="script">
输出脚本<
/param>
public static void ResponseScript(System.Web.UI.Page page, string script)
//page.RegisterStartupScript("message", "<
script language=javascript defer>
" + script + "<
/script>
");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<
script language=javascript defer>
" + script + "<
/script>
");
#endregion
推荐阅读
- #yyds干货盘点# JavaSE系列Java类与对象,万物皆对象
- 自定义验证控件CustomValidator的使用
- wordpress-如何在主页上显示一个类别的帖子(仅一个类别新闻)而不是全部
- WordPress如何在视图中显示skill1_logo
- WordPress(如何检查搜索结果是否是页面的帖子())
- WordPress(如何最好地由注册系统用户对Woocommerce产品进行分类())
- WordPress的标题透明
- WordPress的get_template_directory_uri()不返回https,仅返回http
- WordPress标题logo大小调整