ClientScript.RegisterStartupScript()「建议收藏」

ClientScript.RegisterStartupScript()「建议收藏」一些客户端脚本usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.HtmlControls;usingSystem.Web.UI.WebControls…

大家好,又见面了,我是你们的朋友全栈君。

一些客户端脚本

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace MyBlog.WEB
{

    public class PageBase : System.Web.UI.Page
    {

        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name=”sInputString”>需要加密的字符串</param>
        /// <returns>加密后字符串</returns>
        public static string HashString(string sInputString)
        {

            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sInputString, “MD5”);
        }

        /// <summary>
        /// MessageBox提示框
        /// </summary>
        /// <param name=”Message”>提示信息</param>
        public void MsgBox(string Message)
        {

            ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘” + Message + “‘);</script>”);
            return;
        }

        /// <summary>
        /// MessageBox提示并转向新页面
        /// </summary>
        /// <param name=”Message”>提示信息</param>
        /// <param name=”URL”>跳转的路径</param>
        public void MsgBox(string Message, string URL)
        {

            ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘” + Message + “‘);window.location='” + URL + “‘;</script>”);
            return;
        }
        /// <summary>
        /// 弹出新窗口
        /// </summary>
        /// <param name=”pagePath”>页面路径</param>
        /// <param name=”winName”>新窗口名称</param>
        /// <param name=”winWidth”>新窗口宽度</param>
        /// <param name=”winHeight”>新窗口高度</param>
        public void openNewWin(string pagePath, string winName, int winWidth, int winHeight)
        {

            ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>window.open(‘” + pagePath + “‘,'” + winName + “‘,’toolbar=no,menubar=no,titlebar=no,directories=no,resizable=no,scroll=yes,status=no,fullscreen=no,center=yes,width=” + winWidth + “,height=” + winHeight + “‘);</script>”);
            return;
        }

        /// <summary>
        /// 弹出模态窗口
        /// </summary>
        /// <param name=”pagePath”>页面路径</param>
        /// <param name=”winWidth”>窗口宽度</param>
        /// <param name=”winHeight”>窗口高度</param>
        public void openModelWin(string pagePath, int winWidth, int winHeight)
        {

            string temp;
            temp = @”<script language=’javascript’>”;
            temp += (@”   var sPath ='” + pagePath + “‘;”);
            temp += (@”         strFeatures =’dialogWidth=” + winWidth + “px;dialogHeight=” + winHeight + “px;center=yes;scroll=no;help=no;status: No’;”);
            temp += (@”         var returnvalue = window.showModalDialog(sPath,’brower’,strFeatures);”);
            temp += (@”</script>”);

            ClientScript.RegisterStartupScript(this.GetType(), “message”, temp);
        }

        /// <summary>
        /// 弹出控制父窗口的模态窗口
        /// </summary>
        /// <param name=”pagePath”>页面路径</param>
        /// <param name=”winWidth”>窗口宽度</param>
        /// <param name=”winHeight”>窗口高度</param>
        /// <param name=”frameshref”>控制父窗口路径</param>
        public void openModelWin(string pagepath, int width, int height, string frameshref)
        {

            string temp = @”<script language=’javascript’>”;
            temp += (@”   var sPath ='” + pagepath + “‘;”);
            temp += (@”         strFeatures =’dialogWidth=” + width + “px;dialogHeight=” + height + “px;center=yes;scroll=no;help=no;status=no’;”);
            temp += (@”         var returnvalue = window.showModalDialog(sPath,’brower’,strFeatures);”);
            temp += (@”         window.location.href = ‘” + frameshref + “‘;”);
            temp += (@”</script>”);

            ClientScript.RegisterStartupScript(this.GetType(), “message”, temp);
        }

        /// <summary>
        /// 关闭本窗口
        /// </summary>
        public void CloseWin()
        {

            ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>window.opener=null;window.close();</script>”);
            return;
        }

        /// <summary>
        /// 弹出提示信息,并关闭本窗口
        /// <param name=”Words”>弹出提示信息内容</param>
        /// </summary>
        public void CloseWin(string Words)
        {

            ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘”+Words+”‘);window.opener=null;window.close();</script>”);
            return;
        }

        /// <summary>
        /// 关闭本窗口并,重新加载父窗口.
        /// </summary>
        /// <param name=”URL”>父窗口要加载的URL</param>
        public void reLoadParentAndClose(string URL)
        {

            ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>window.opener.location='” + URL + “‘;window.close();</script>”);
            return;
        }

        /// <summary>
        /// 显示提示信息,关闭本窗口并,重新加载父窗口.
        /// </summary>
        /// <param name=”Words”>提示消息内容</param>
        /// <param name=”URL”>父窗口要加载的URL</param>
        public void ShowWords_reLoadParentAndClose(string Words,string URL)
        {

            ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘” + Words
+ “‘); window.opener.location='” + URL + “‘;window.close();</script>”);
            return;
        }

        /// <summary>
        /// 获取客户端IP
        /// </summary>
        /// <returns></returns>
        public string GetClientIP()
        {

            string result = HttpContext.Current.Request.ServerVariables[“HTTP_X_FORWARDED_FOR”];
            if (null == result || result == String.Empty)
            {

                result = HttpContext.Current.Request.ServerVariables[“REMOTE_ADDR”];
            }

            if (null == result || result == String.Empty)
            {

                result = HttpContext.Current.Request.UserHostAddress;
            }
            return result;
        }

/// <summary>
        /// 获取Session值
        /// </summary>
        /// <param name=”SessionID”>要获取的Session值</param>
        /// <returns></returns>
        public string GetSession(string SessionID)
        {

            string restr = “unkown”;
            try
            {

                restr = Session[SessionID].ToString();
            }
            catch
            {

            }
            if (restr == “unkown” && restr == null && restr == “”)
            {

                Response.Redirect(“/Error.aspx?Type=NoPopedom”);
            }
            return restr;
        }

        /// <summary>
        /// 写Cookie
        /// </summary>
        /// <param name=”CookiesName”>Cookie集名称</param>
        /// <param name=”name”>Cookie名</param>
        /// <param name=”Value”>值</param>
        public void WritCookie(string CookiesName, string name, string Value)
        {

            HttpCookie cookie = new HttpCookie(CookiesName);
            cookie.Values.Add(name, Value);
            Response.AppendCookie(cookie);
        }

        /// <summary>
        /// 获取Cookie
        /// </summary>
        /// <param name=”CookiesName”>Cookie集名称</param>
        /// <param name=”name”>Cookie名</param>
        /// <param name=”Value”>值</param>
        public string GetCookie(string CookiesName, string name)
        {

            string value = string.Empty;
            try
            {

                HttpCookie cookie = Request.Cookies[CookiesName];
                value = cookie.Values[name];
            }
            catch
            {

                Response.Redirect(“/Error.aspx?Type=GetCookie”);
            }
            return value;
        }
    }
}

转载于:https://www.cnblogs.com/softwareking/archive/2011/03/19/1988570.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/162301.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • Java数组超详解

    Java数组超详解一、前言前面我们学习了随机数的介绍和使用,那么这篇我们来学习java中数组的定义和使用,java的数组和c语言的十分类似。二、数组的定义数组定义的形式:格式1:数据类型[]数组名;如int[]arr;说明:定义了一个int类型的数组,数组名是arr格式2:数据类型数组名[];如intarr[];说明:定义了一个int类型的数组名是arr的数组…

  • PahoMQTT_mqtt安装

    PahoMQTT_mqtt安装1.安装npminstall paho-mqtt-s2.初始化constPahoMQTT=require(‘paho-mqtt’)constname=newDate().getTime()+’client’constclient=newPahoMQTT.Client(‘www.100link.net’,Number(61615),nam…

    2022年10月31日
  • 如何用pycharm编写程序_pycharm怎么编写python代码

    如何用pycharm编写程序_pycharm怎么编写python代码一、编写第一个Python项目二、使用Pycharm编写第一个Python程序运行Pycharm,选择CreateNewProject,创建一个新的Python工程。选择’PurePython’创建一个新的纯Python工程项目,Location表示该项目的保存路径,Interpreter用来指定Python计时器的版本。右击项目,选择New,再选择PythonFile在…

  • 免费 UML 工具

    免费 UML 工具选取了四款UML工具:astah经常看到网上的黄色背景就是这个软件画的,最后一个免费的社区版本是:astahcommunity7.2安装包大小50M以下三个均为免费版本:SoftwareIdeasModeler可以画序列图,安装包很小,只有十几兆,而且提供便携版下载Modelio这是一个大型的软件,安装包300+MBModelio是由位于法国巴黎的Modeliosoft开发的开源UML工具。它支持UML2和BPMN标准。BOUML看起来…

  • ssh远程连接失败_ssh connect to host port 22

    ssh远程连接失败_ssh connect to host port 22不少人在ssh连接远程机器时遇到过ssh_exchange_identification:Connectionclosedbyremotehost的问题,在网上找了一堆教程试了都不行,博主总结了常见的几种解决方法(以Ubuntu18.04为例)。可能原因1:没装openssh-server;解决方案:sudoaptinstallopenssh-server或者sudoapt-getinstallopenssh-server可能原因2:连接超过了MaxSession

  • vagrant配置端口转发

    vagrant配置端口转发

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号