C#完成客戶端彈出新聞框封裝類實例。本站提示廣大學習愛好者:(C#完成客戶端彈出新聞框封裝類實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成客戶端彈出新聞框封裝類實例正文
本文實例講述了C#完成客戶端彈出新聞框封裝類。分享給年夜家供年夜家參考。詳細以下:
asp.net在辦事器端運轉,是不克不及在辦事器端彈出對話框的,然則C#可以經由過程在頁面輸入JS代碼完成彈出新聞框的後果,這個C#類封裝了經常使用的新聞框彈出JS代碼,可以在辦事器端挪用,在客戶端顯示對話框。不只可以顯示JS的正告框,還可以顯示形式窗口,異常便利。
using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace DotNet.Utilities { /// <summary> /// 頁面經常使用辦法包裝 /// </summary> public class ShowMessageBox { #region 信息顯示 /// <summary> /// 顯示提醒信息 /// </summary> /// <param name="message"></param> public static void ShowMG(string message) { WriteScript("alert('" + message + "');"); } /// <summary> /// 顯示提醒信息 /// </summary> /// <param name="message">提醒信息</param> public static void ShowMessage(string message) { ShowMessage("體系提醒", 180, 120, message); } /// <summary> /// 顯示提醒信息 /// </summary> /// <param name="message">提醒信息</param> public static void ShowMessage_link(string message, string linkurl) { ShowMessage_link("體系提醒", 180, 120, message, linkurl, 8000, -1); } /// <summary> /// 顯示提醒信息 /// </summary> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="message">提醒信息</param> private static void ShowMessage(string title, int width, int height, string message) { ShowMessage(title, width, height, message, 3000, -1); } /// <summary> /// 顯示提醒信息 /// </summary> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="message"></param> /// <param name="delayms"></param> /// <param name="leftSpace"></param> private static void ShowMessage(string title, int width, int height, string message, int delayms, int leftSpace) { WriteScript(string.Format("popMessage({0},{1},'{2}','{3}',{4},{5});", width, height, title, message, delayms, leftSpace == -1 ? "null" : leftSpace.ToString())); } /// <summary> /// 顯示提醒信息 /// </summary> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="message"></param> /// <param name="delayms"></param> /// <param name="leftSpace"></param> private static void ShowMessage_link(string title, int width, int height, string message, string linkurl, int delayms, int leftSpace) { WriteScript(string.Format("popMessage2({0},{1},'{2}','{3}','{4}',{5},{6});", width, height, title, message, linkurl, delayms, leftSpace == -1 ? "null" : leftSpace.ToString())); } #endregion #region 顯示異常信息 /// <summary> /// 顯示異常信息 /// </summary> /// <param name="ex"></param> public static void ShowExceptionMessage(Exception ex) { ShowExceptionMessage(ex.Message); } /// <summary> /// 顯示異常信息 /// </summary> /// <param name="message"></param> public static void ShowExceptionMessage(string message) { WriteScript("alert('" + message + "');"); //PageHelper.ShowExceptionMessage("毛病提醒", 210, 125, message); } /// <summary> /// 顯示異常信息 /// </summary> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="message"></param> private static void ShowExceptionMessage(string title, int width, int height, string message) { WriteScript(string.Format("setTimeout(\"showAlert('{0}',{1},{2},'{3}')\",100);", title, width, height, message)); } #endregion #region 顯示模態窗口 /// <summary> /// 前往把指定鏈接地址顯示模態窗口的劇本 /// </summary> /// <param name="wid"></param> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="url"></param> public static string GetShowModalWindowScript(string wid, string title, int width, int height, string url) { return string.Format("setTimeout(\"showModalWindow('{0}','{1}',{2},{3},'{4}')\",100);", wid, title, width, height, url); } /// <summary> /// 把指定鏈接地址顯示模態窗口 /// </summary> /// <param name="wid">窗口ID</param> /// <param name="title">題目</param> /// <param name="width">寬度</param> /// <param name="height">高度</param> /// <param name="url">鏈接地址</param> public static void ShowModalWindow(string wid, string title, int width, int height, string url) { WriteScript(GetShowModalWindowScript(wid, title, width, height, url)); } /// <summary> /// 為指定控件綁定前台劇本:顯示模態窗口 /// </summary> /// <param name="control"></param> /// <param name="eventName"></param> /// <param name="wid"></param> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="url"></param> /// <param name="isScriptEnd"></param> public static void ShowCilentModalWindow(string wid, WebControl control, string eventName, string title, int width, int height, string url, bool isScriptEnd) { string script = isScriptEnd ? "return false;" : ""; control.Attributes[eventName] = string.Format("showModalWindow('{0}','{1}',{2},{3},'{4}');" + script, wid, title, width, height, url); } /// <summary> /// 為指定控件綁定前台劇本:顯示模態窗口 /// </summary> /// <param name="cell"></param> /// <param name="eventName"></param> /// <param name="wid"></param> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="url"></param> /// <param name="isScriptEnd"></param> public static void ShowCilentModalWindow(string wid, TableCell cell, string eventName, string title, int width, int height, string url, bool isScriptEnd) { string script = isScriptEnd ? "return false;" : ""; cell.Attributes[eventName] = string.Format("showModalWindow('{0}','{1}',{2},{3},'{4}');" + script, wid, title, width, height, url); } #endregion #region 顯示客戶端確認窗口 /// <summary> /// 顯示客戶端確認窗口 /// </summary> /// <param name="control"></param> /// <param name="eventName"></param> /// <param name="message"></param> public static void ShowCilentConfirm(WebControl control, string eventName, string message) { ShowCilentConfirm(control, eventName, "體系提醒", 210, 125, message); } /// <summary> /// 顯示客戶端確認窗口 /// </summary> /// <param name="control"></param> /// <param name="eventName"></param> /// <param name="title"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="message"></param> public static void ShowCilentConfirm(WebControl control, string eventName, string title, int width, int height, string message) { control.Attributes[eventName] = string.Format("return showConfirm('{0}',{1},{2},'{3}','{4}');", title, width, height, message, control.ClientID); } #endregion /// <summary> /// 寫javascript劇本 /// </summary> /// <param name="script">劇本內容</param> public static void WriteScript(string script) { Page page = GetCurrentPage(); // NDGridViewScriptFirst(page.Form.Controls, page); page.ClientScript.RegisterStartupScript(page.GetType(), System.Guid.NewGuid().ToString(), script, true); } /// <summary> /// 獲得以後頁對象實例 /// </summary> /// <returns></returns> public static Page GetCurrentPage() { return (Page)HttpContext.Current.Handler; } } }
願望本文所述對年夜家的C#法式設計有所贊助。