Asp.net 彈出對話方塊基類(輸出alet警告框)

來源:互聯網
上載者:User

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
namespace EC
{
/// <summary>
/// 資訊輸出通用方法
/// </summary>
public class MessageObject
{
/// <summary>
/// 一般輸出
/// </summary>
/// <param name="str"></param>
public static void Write(string str)
{
System.Web.HttpContext.Current.Response.Write(str);
}
/// <summary>
/// 顯示一段自訂的輸出代碼
/// </summary>
/// <param name="MyPage"></param>
/// <param name="strCode"></param>
public static void ShowJS(System.Web.UI.Page MyPage, string strCode)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\"> \n");
sb.Append(strCode.Trim());
sb.Append("</script>");
MyPage.Response.Write(sb.ToString());
}
/// <summary>
/// 頁面重載
/// </summary>
public static void Location()
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\"> \n");
sb.Append("window.location.href=window.location.href;");
sb.Append("</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
/// <summary>
/// 顯示一個快顯視窗
/// </summary>
/// <param name="str"></param>
public static void Show(string str)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\"> \n");
sb.Append("alert(\"" + str.Trim() + "\"); \n");
sb.Append("</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
/// <summary>
/// 顯示一個快顯視窗,並關閉當前頁
/// </summary>
/// <param name="str"></param>
public static void ShowClose(string str)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language=\"javascript\">\n");
sb.Append("alert(\"" + str.Trim() + "\"); \n");
sb.Append("window.close();\n");
sb.Append("</script>\n");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
/// <summary>
/// 顯示一個快顯視窗,並轉向當前頁(重新整理)
/// </summary>
/// <param name="str"></param>
public static void ShowLocation(string str)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\"> \n");
sb.Append("alert(\"" + str.Trim() + "\"); \n");
sb.Append("window.location.href=window.location.href;\n");
sb.Append("</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
/// <summary>
/// 顯示一個快顯視窗,並轉向目標頁(導航)
/// </summary>
/// <param name="str"></param>
/// <param name="url"></param>
public static void ShowRedirect(string str, string url)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\"> \n");
sb.Append("alert(\"" + str.Trim() + "\"); \n");
sb.Append("window.location.href=\"" + url.Trim() + "\";\n");
sb.Append("</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
/// <summary>
/// 顯示一個快顯視窗,並轉向上一頁
/// </summary>
/// <param name="str"></param>
public static void ShowPre(string str)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\"> \n");
sb.Append("alert(\"" + str.Trim() + "\"); \n");
sb.Append("var p=document.referrer; \n");
sb.Append("window.location.href=p;\n");
sb.Append("</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
/// <summary>
/// 重新導向
/// </summary>
/// <param name="url"></param>
public static void RedirectPage(string url)
{
string path = "http://" + System.Web.HttpContext.Current.Request.Url.Host + url;
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\"> \n");
sb.Append(string.Format("window.location.href='{0}';", @path));
sb.Append("</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
}
}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.