C # implements a client popup message box wrapper class

Source: Internet
Author: User
ASP. NET run on the server side, is not on the server-side popup dialog box, but C # can be achieved by the page output JS code to implement the pop-up message box effect, this C # class encapsulates the common message box popup JS code, can be called on the server side, the Client Display dialog box. Not only can display the JS warning box, also can display the modal window, very convenient.

Using system;using system.web;using system.web.ui;using System.Web.UI.WebControls; Namespace dotnet.utilities{///// page Common method packaging //public class ShowMessageBox {#region information displayed////// Display message //////public static void SHOWMG (String message) {Writescript ("alert ('" + Message + "');");} ////// Display message //////Prompt informationpublic static void ShowMessage (String message) {ShowMessage ("system hint", +/-+, message); }            ////// Display message //////Prompt informationpublic static void Showmessage_link (String message, String linkurl) {showmessage_link ("system hint", 180, 120,        Message, Linkurl, 8000,-1); }          ////// Display message ///////////////Prompt informationprivate static void ShowMessage (string title, int width, int height, string message) {ShowMessage (title        , width, height, message, 3000,-1); }          ////// Display message /////////////////////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 ())); }            ////// Display message /////////////////////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 Show exception information///// Show exception information //////public static void Showexceptionmessage (Exception ex) {Showexceptionmessage (ex).        Message); }          ////// Show exception information //////public static void Showexceptionmessage (String message) {Writescript ("alert ('" + Message + "');");        Pagehelper.showexceptionmessage ("Error hint", "a", ","); }          ////// Show exception information ///////////////private static void Showexceptionmessage (string title, int width, int height, string message) {WRITESCR IPT (String.        Format ("SetTimeout (\" Showalert (' {0} ', {1},{2}, ' {3} ') \ ", +);", title, width, height, message); } #endregion #region Display modal window///// Returns the script that displays the modal window with the specified link address /////////////////public static string Getshowmodalwindowscript (String wid, string title, int width, int height, string url) { return string.        Format ("SetTimeout (\" Showmodalwindow (' {0} ', ' {1} ', {2},{3}, ' {4} ') \ ", +);", Wid, title, width, height, url); }          ////// display the modal window with the specified link address //////Window ID///Title///Width///Height///Link Addresspublic static void Showmodalwindow (String wid, string title, int width, int height, string url) {writes        Cript (Getshowmodalwindowscript (WID, title, width, height, url)); }          //////Bind foreground script for specified control: Display modal window///////////////////////////public static void Showcilentmodalwindow (String wid, WebControl control, String eventName, string title, int width, int he ight, 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); }          //////Bind foreground script for specified control: Display modal window///////////////////////////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 Display the Client confirmation window////// Show Client Confirmation window ////////////public static void Showcilentconfirm (WebControl control, String eventName, String message) {SHOWCILENTC        Onfirm (Control, EventName, "system hint", "a", ","); }          ////// Show Client Confirmation window /////////////////////public static void Showcilentconfirm (WebControl control, String eventName, string title, int width, int height, string mes Sage) {control. Attributes[eventname] = string. Format ("Return showconfirm (' {0} ', {1},{2}, ' {3} ', ' {4} ');", title, width, height, message, control.        ClientID); } #endregion////// write JavaScript script //////Script Contentpublic static void Writescript (String script) {Page page = Getcurrentpage (); Ndgridviewscriptfirst (page.              Form.controls, page); Page. Clientscript.registerstartupscript (page. GetType (), System.Guid.NewGuid ().          ToString (), script, true); }          ////// Get the current Page object instance /////
 
  
 public static Page Getcurrentpage () {return (page) HttpContext.Current.Handler; }        }}
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.