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);
            }

  • 相关阅读:
    HDU 1850 Being a Good Boy in Spring Festival
    UESTC 1080 空心矩阵
    HDU 2491 Priest John's Busiest Day
    UVALive 6181
    ZOJ 2674 Strange Limit
    UVA 12532 Interval Product
    UESTC 1237 质因子分解
    UESTC 1014 Shot
    xe5 android listbox的 TMetropolisUIListBoxItem
    xe5 android tts(Text To Speech)
  • 原文地址:https://www.cnblogs.com/xiaobaigang/p/821121.html
Copyright © 2011-2022 走看看