zoukankan      html  css  js  c++  java
  • 常用的弹出窗口类

        public class Alert
        {

            #region 警告函数
            ///<summary>
            /// 写警告,仅弹出对话框
            ///</summary>
            public static void MessageBox(string text)//弹出对话框
            {
                HttpContext.Current.Response.Write("<Script language=javascript>alert('" + text + "');</script>");
            }
            ///<summary>
            /// 写警告,仅弹出对话框关闭窗口
            ///</summary>
            public static void MessageBoxClose(string text)//弹出对话框
            {
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window.close()");
                HttpContext.Current.Response.Write("</script>");
            }

            ///<summary>
            /// 写警告,返回原来页面
            ///</summary>
            public static void MessageBoxBack(string text)//返回原来页面
            {
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window.history.go(-1)");
                HttpContext.Current.Response.Write("</script>");
            }
            ///<summary>
            /// 页面转向
            /// text 警告文本,转向页面,转向目标
            ///</summary>
            public static void MessageBoxRedirect(string text, string gourl, string target)
            {
                if (target == "" || target == null)
                { target = "window"; }
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window." + target + ".location='" + gourl + "';");
                HttpContext.Current.Response.Write("</script>");
            }
            ///<summary>
            /// 页面转向
            /// text 警告文本,转向页面
            ///</summary>
            public static void MessageBoxRedirect(string text, string gourl)
            {
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window.location='" + gourl + "';");
                HttpContext.Current.Response.Write("</script>");
            }
            #endregion


            /// <summary>
            /// 处理用户输入的危险代码
            /// </summary>
            ///定义InputText函数处理用于输入
            public static string InputText(string inputString, int maxLength)
            {
                StringBuilder retVal = new StringBuilder();     ///构造临时字符串数组
                if ((inputString != null) && (inputString != String.Empty))
                {
                    inputString = inputString.Trim();         ///清空字符串两段的空白符号
                    if (inputString.Length > maxLength)
                    {   ///设置字符串的长度
                        inputString = inputString.Substring(0, maxLength);
                    }
                    for (int i = 0; i < inputString.Length; i++)
                    {
                        switch (inputString[i])
                        {
                            ///去除危险字符串(\ ,/,:,*,?,",<,>,| )
                            case '*':
                            case '|':
                            case '<':
                            case '>':
                            case '/':
                            case '\\':
                            case ':':
                            case '?':
                            case '"':
                                retVal.Append(""); break;
                            default: retVal.Append(inputString[i]); break;
                        }
                    }
                    retVal.Replace("'", " ");
                }
                return retVal.ToString();
            }

     /// <summary>
            /// 动态加载下拉菜单
            /// </summary>
            public static void AddListItem(ListControl control, string value, string text)
            {
                ListItem item = new ListItem();
                item.Text = text;
                item.Value = value;
                control.Items.Add(item);
            }

  • 相关阅读:
    Python基础-time and datetime
    Python基础-包
    Python基础-常用模块
    第四十七天Python学习记录
    第四十四天Python学习记录
    如何教你在NIPS会议上批量下载历年的pdf文档(另附04~14年NIPS论文下载链接)
    如何用pdfbox-app-1.8.10.jar批处理将pdf文档转换成text文档
    如何在Win10下设置图片的浏览方式为windows照片查看器
    如何不通过系统升级来安装window10正式版?(特别针对Xp用户)
    Mysql统计信息处理及binlog解释
  • 原文地址:https://www.cnblogs.com/xiaobaigang/p/821172.html
Copyright © 2011-2022 走看看