程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> Asp.net 彈出對話框基類(輸出alet警告框)

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

編輯:ASP.NET基礎
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());
}
}
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved