• 常用的弹出窗口类


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

  • 相关阅读:
    Java集合HashMap的实现原理(借鉴)
    Heritrix在eclipse中的配置
    Hadoop中涉及到的网络 I/O 优化
    李开复的博士论文人生思考
    Java中HastSet用法
    统计语言模型
    ASP.NET 中的正则表达式
    高ASP.Net应用程序性能的十大方法
    在多线程环境下使用HttpWebRequest或者调用Web Service
    使用TextBoxWatermark为TextBox加上水印效果
  • 原文地址:https://www.cnblogs.com/xiaobaigang/p/821172.html
Copyright © 2020-2023  润新知