ASP.NET中常用输出JS脚本的类(来自于周公博客)
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- /// <summary>
- /// 一些常用的Js调用
- /// 采用ClientScript.RegisterStartupScript(string msg)的方式输出,不会改变xhtml的结构,
- /// 不会影响执行效果。
- /// 为了向下兼容,采用了重载的方式,新版本中要求一个System.Web.UI.Page类的实例。
- /// </summary>
- public class JScript
- {
- #region 实现方法
- /// <summary>
- /// 弹出JavaScript小窗口
- /// </summary>
- /// <param name="js">窗口信息</param>
- public static void Alert(string message, Page page)
- {
- #region
- string js = @"<Script language='JavaScript'>
- alert('" + message + "');</Script>";
- //HttpContext.Current.Response.Write(js);
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "alert"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "alert", js);
- }
- #endregion
- }
- /// <summary>
- /// 弹出消息框并且转向到新的URL
- /// </summary>
- /// <param name="message">消息内容</param>
- /// <param name="toURL">连接地址</param>
- public static void AlertAndRedirect(string message, string toURL, Page page)
- {
- #region
- string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
- //HttpContext.Current.Response.Write(string.Format(js, message, toURL));
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "AlertAndRedirect"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "AlertAndRedirect", string.Format(js, message, toURL));
- }
- #endregion
- }
- /// <summary>
- /// 回到历史页面
- /// </summary>
- /// <param name="value">-1/1</param>
- public static void GoHistory(int value, Page page)
- {
- #region
- string js = @"<Script language='JavaScript'>
- history.go({0});
- </Script>";
- //HttpContext.Current.Response.Write(string.Format(js, value));
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "GoHistory"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "GoHistory", string.Format(js, value));
- }
- #endregion
- }
- // /// <summary>
- // /// 关闭当前窗口
- // /// </summary>
- // public static void CloseWindow()
- // {
- // #region
- // string js = @"<Script language='JavaScript'>
- // parent.opener=null;window.close();
- // </Script>";
- // HttpContext.Current.Response.Write(js);
- // HttpContext.Current.Response.End();
- // #endregion
- // }
- /// <summary>
- /// 刷新父窗口
- /// </summary>
- public static void RefreshParent(string url, Page page)
- {
- #region
- string js = @"<Script language='JavaScript'>
- window.opener.location.href='" + url + "';window.close();</Script>";
- //HttpContext.Current.Response.Write(js);
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshParent"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshParent", js);
- }
- #endregion
- }
- /// <summary>
- /// 刷新打开窗口
- /// </summary>
- public static void RefreshOpener(Page page)
- {
- #region
- string js = @"<Script language='JavaScript'>
- opener.location.reload();
- </Script>";
- //HttpContext.Current.Response.Write(js);
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshOpener"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshOpener", js);
- }
- #endregion
- }
- /// <summary>
- /// 打开指定大小的新窗体
- /// </summary>
- /// <param name="url">地址</param>
- /// <param name="width">宽</param>
- /// <param name="heigth">高</param>
- /// <param name="top">头位置</param>
- /// <param name="left">左位置</param>
- public static void OpenWebFormSize(string url, int width, int heigth, int top, int left, Page page)
- {
- #region
- string js = @"<Script language='JavaScript'>window.open('" + url + @"','','height=" + heigth + ",width=" + width + ",top=" + top + ",left=" + left + ",location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');</Script>";
- //HttpContext.Current.Response.Write(js);
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "OpenWebFormSize"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "OpenWebFormSize", js);
- }
- #endregion
- }
- /// <summary>
- /// 转向Url制定的页面
- /// </summary>
- /// <param name="url">连接地址</param>
- public static void JavaScriptLocationHref(string url, Page page)
- {
- #region
- string js = @"<Script language='JavaScript'>
- window.location.replace('{0}');
- </Script>";
- js = string.Format(js, url);
- //HttpContext.Current.Response.Write(js);
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "JavaScriptLocationHref"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "JavaScriptLocationHref", js);
- }
- #endregion
- }
- /// <summary>
- /// 打开指定大小位置的模式对话框
- /// </summary>
- /// <param name="webFormUrl">连接地址</param>
- /// <param name="width">宽</param>
- /// <param name="height">高</param>
- /// <param name="top">距离上位置</param>
- /// <param name="left">距离左位置</param>
- public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left, Page page)
- {
- #region
- string features = "dialogWidth:" + width.ToString() + "px"
- + ";dialogHeight:" + height.ToString() + "px"
- + ";dialogLeft:" + left.ToString() + "px"
- + ";dialogTop:" + top.ToString() + "px"
- + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
- ShowModalDialogWindow(webFormUrl, features, page);
- #endregion
- }
- /// <summary>
- /// 弹出模态窗口
- /// </summary>
- /// <param name="webFormUrl"></param>
- /// <param name="features"></param>
- public static void ShowModalDialogWindow(string webFormUrl, string features, Page page)
- {
- string js = ShowModalDialogJavascript(webFormUrl, features);
- //HttpContext.Current.Response.Write(js);
- if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "ShowModalDialogWindow"))
- {
- page.ClientScript.RegisterStartupScript(page.GetType(), "ShowModalDialogWindow", js);
- }
- }
- private static string ShowModalDialogJavascript(string webFormUrl, string features)
- {
- throw new NotImplementedException();
- }
- // /// <summary>
- // /// 弹出模态窗口
- // /// </summary>
- // /// <param name="webFormUrl"></param>
- // /// <param name="features"></param>
- // /// <returns></returns>
- // public static string ShowModalDialogJavascript(string webFormUrl, string features)
- // {
- // #region
- // string js = @"<script language=javascript>
- // showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
- // return js;
- // #endregion
- // }
- #endregion
- }
ASP.NET中常用输出JS脚本的类(来自于周公博客)的更多相关文章
- ASP.NET中后台注册js脚本攻略(转)
用Page.ClientScript.RegisterClientScriptBlock 和Page.ClientScript.RegisterStartupScript:区别: 1.使用Page ...
- ASP.NET中常用的几个李天平开源公共类LTP.Common,Maticsoft.DBUtility,LtpPageControl
ASP.NET中常用的几个开源公共类: LTP.Common.dll: 通用函数类库 源码下载Maticsoft.DBUtility.dll 数据访问类库组件 源码下载LtpPageC ...
- ASP.NET中常用的几个李天平开源公共类LTP.Common,Maticsoft.DBUtility,LtpPageControl (转)
ASP.NET中常用的几个开源公共类: LTP.Common.dll: 通用函数类库 源码下载Maticsoft.DBUtility.dll 数据访问类库组件 源码下载LtpPageC ...
- C#中如何使用JS脚本
C#中如何使用JS脚本 目前在做的组态软件中就使用到了js脚本,这部分js脚本是供用户编写的,用户可以通过我们提供的脚本以及js自身的逻辑,用户就可以随心所欲的控制设备的运行.有比较了几款在C#中执行 ...
- 请解释ASP. NET中的web页面与隐藏类之间的关系
请解释ASP.NET中的web页面与其隐藏类之间的关系 其实页面与其隐藏类之间就是一个部分类的关系,你在页面上放一个一个的控件就是在这个类中定义一个一个的属性, 因为是同一个类的部分类的关系,所以隐藏 ...
- 分享Node.js + Koa2 + MySQL + Vue.js 实战开发一套完整个人博客项目网站
这是个什么的项目? 使用 Node.js + Koa2 + MySQL + Vue.js 实战开发一套完整个人博客项目网站. 博客线上地址:www.boblog.com Github地址:https: ...
- python中逐行读取文件的最佳方式_Drupal_新浪博客
python中逐行读取文件的最佳方式_Drupal_新浪博客 python中逐行读取文件的最佳方式 (2010-08-18 15:59:28) 转载▼ 标签: python ...
- LIGHTX-CMS —— 基于 Node.js,Express.js 以及 SQLite 3 搭建的个人博客系统
概述 LIGHTX-CMS 是我基于 Node.js,Express.js 以及 SQLite 3 搭建的个人博客发布系统. 项目本身可以拿来部署个人博客网站,同时我认为其也适合用以新手学习 Node ...
- C#获取C# DLL中的指定接口的所有实现实例 - qq_19759475的博客 - CSDN博客
原文:C#获取C# DLL中的指定接口的所有实现实例 - qq_19759475的博客 - CSDN博客 public static List<T> CreateTarInterface& ...
随机推荐
- TCP系列54—拥塞控制—17、AQM及ECN
一.概述 ECN的相关内容是在RFC3168中定义的,这里我简单描述一下RFC3168涉及的主要内容. 1.AQM和RED 目前TCP中多数的拥塞控制算法都是通过缓慢增加拥塞窗口直到检测到丢包来进行慢 ...
- 深入理解JAVA集合系列一:HashMap源码解读
初认HashMap 基于哈希表(即散列表)的Map接口的实现,此实现提供所有可选的映射操作,并允许使用null值和null键. HashMap继承于AbstractMap,实现了Map.Cloneab ...
- 关于SVM数学细节逻辑的个人理解(二):从基本形式转化为对偶问题
第二部分:转化为对偶问题进一步简化 这一部分涉及的数学原理特别多.如果有逻辑错误希望可以指出来. 上一部分得到了最大间隔分类器的基本形式: 其中i=1,2,3...m 直接求的话一看就很复杂,我们 ...
- 'java' 不是内部或外部命令,也不是可运行的程序的两个解决办法
第一个原因: 是环境变量path没有配置好,做如下图配置 第二个原因: 如果java环境有一段时间没有启动,再启动的时候提示这个,解决办法是进入path环境配置,如上图中界面,将JAVA_ ...
- D3.js 入门学习(二) V4的改动
//d3.scan /* 新的d3.scan方法对数组进行线性扫描,并根据指定的比较函数返回至少一个元素的索引. 这个方法有点类似于d3.min和d3.max. 而d3.scan可以得到极值的索引而不 ...
- express和数据库(MySQL)的交互(二)
一.安装express前面都讲了 1.express. cnpm || npm install express --save 2.中间件 a.cnpm || npm install body-pars ...
- VNC Server (CentOS 7 GNOME)
1. 安装VNC服务 sudo yum install tigervnc-server -y 2. 启动VNC服务,设置密码,然后停止 vncserver :1 vncserver -kill :1 ...
- <script>document.write(location.href)</script>
<script>document.write(location.href)</script> 什么意思?
- python自动化之邮件发送
#!/usr/bin/env python # -*- coding:utf-8 -*- import smtplib from email.mime.multipart import MIMEMul ...
- DPM(Deformable Parts Model)
DPM(Deformable Parts Model) Reference: Object detection with discriminatively trained partbased mode ...