C# 后台调用script使用类
在网站的开发的时候,总是会用到一些前台的提示的script的代码,从项目中整理了一份常用的方法。
public class Jscript
{
public Jscript()
{
//
// TODO: 在此处添加构造函数逻辑
//
} /// <summary>
/// 跳转页面
/// </summary>
/// <param name="url"></param>
public static void RedirectTo(string url)
{
HttpContext.Current.Response.Write("<script>window.top.location.href='" + url + "'</script>");
} /// <summary>
/// 服务器端弹出alert对话框
/// </summary>
/// <param name="str_Message">提示信息,例子:"请输入您姓名!"</param>
/// <param name="page">Page类</param>
public static void Alert(string str_Message, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert('" + str_Message + "');</script>");
} /// <summary>
/// 系统自定义提示
/// </summary>
public static void DamicAlert()
{
Jscript.AlertAndRedirectJstr("您访问的数据不存在!", "window.history.go(-1);");
} /// <summary>
/// 自己插入脚本
/// </summary>
/// <param name="str_Message">提示信息</param>
/// <param name="url">脚本设置</param>
public static void AlertAndRedirectJstr(string str_Message, string strjs)
{
HttpContext.Current.Response.Write("<script>alert('" + str_Message + "');" + strjs + "</script>");
HttpContext.Current.Response.End();
} /// <summary>
/// 权限跳转页面
/// </summary>
/// <param name="str_Message">提示信息</param>
/// <param name="url">跳转页面</param>
public static void PopedomRedirect(string str_Message, string url)
{
HttpContext.Current.Response.Write("<script>alert('" + str_Message + "');window.top.location.href='" + url + "'</script>");
} /// <summary>
/// 弹出JavaScript小窗口
/// </summary>
/// <param name="js">窗口信息</param>
public static void Alert(string message)
{
#region
string js = @"<Script language='JavaScript'>
alert('" + message + "');</Script>";
HttpContext.Current.Response.Write(js);
#endregion
} /// <summary>
/// 弹出消息框并且转向到新的URL
/// </summary>
/// <param name="message">消息内容</param>
/// <param name="toURL">连接地址</param>
public static void AlertAndRedirect(string message, string toURL)
{
#region
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
HttpContext.Current.Response.Write(string.Format(js, message, toURL));
#endregion
}
public static void AlertAndGoHistory(string message)
{
#region
string js = "<script language=javascript>alert('{0}');history.back();</script>";
HttpContext.Current.Response.Write(string.Format(js, message));
HttpContext.Current.Response.End();
#endregion
}
/// <summary>
/// 回到历史页面
/// </summary>
/// <param name="value">-1/1</param>
public static void GoHistory(int value)
{
#region
string js = @"<Script language='JavaScript'>
history.go({0});
</Script>";
HttpContext.Current.Response.Write(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)
{
#region
string js = @"<Script language='JavaScript'>
window.opener.location.href='" + url + "';window.close();</Script>";
HttpContext.Current.Response.Write(js);
#endregion
}
/// <summary>
/// 刷新父窗口
/// </summary>
public static void RefreshParent()
{
#region
string js = @"<Script language='JavaScript'>
parent.parent.location.href=parent.parent.location.href;
</Script>";
HttpContext.Current.Response.Write(js);
#endregion
} /// <summary>
/// 刷新打开窗口
/// </summary>
public static void RefreshOpener()
{
#region
string js = @"<Script language='JavaScript'>
opener.location.reload();
</Script>";
HttpContext.Current.Response.Write(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)
{
#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);
#endregion
} /// <summary>
/// 转向Url制定的页面
/// </summary>
/// <param name="url">连接地址</param>
public static void JavaScriptLocationHref(string url)
{
#region
string js = @"<Script language='JavaScript'>
window.location.replace('{0}');
</Script>";
js = string.Format(js, url.Replace("'", @"\'"));
HttpContext.Current.Response.Write(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)
{
#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);
#endregion
} public static void ShowModalDialogWindow(string webFormUrl, string features)
{
string js = ShowModalDialogJavascript(webFormUrl, features);
HttpContext.Current.Response.Write(js);
} public static string ShowModalDialogJavascript(string webFormUrl, string features)
{
#region
string js = @"<script language=javascript>
showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
return js;
#endregion
} }
C# 后台调用script使用类的更多相关文章
- js前台与后台数据交互-后台调前台(后台调用、注册客户端脚本)
转自:http://blog.csdn.net/wang379275614/article/details/17049721 客户端脚本一般都在前台,这里讲的是(1)在后台调用前台定义的脚本(2)在后 ...
- js调用.net后台事件,和后台调用前台等方法以及js调用服务器控件的方法
http://blog.csdn.net/deepwishly/article/details/6670942 ajaxPro.dll基础教程(前台调用后台方法,后台调用前台方法) 1. javaS ...
- js调用.net后台事件,和后台调用前台等方法总结(转帖)
js调用.net后台事件,和后台调用前台等方法总结 原文来自:http://hi.baidu.com/xiaowei0705/blog/item/4d56163f5e4bf616bba16725.ht ...
- js调用后台,后台调用前台等方法总结
1. javaScript函数中执行C#代码中的函数:方法一:1.首先建立一个按钮,在后台将调用或处理的内容写入button_click中; 2.在前台写一个js函数,内容为docume ...
- 【转】 C#后台调用前台javascript的五种方法
第一种,OnClientClick (vs2003不支持这个方法)<asp:ButtonID="Button1" runat="server" Te ...
- ASP.NET,C#后台调用前台javascript的五种方法
C#后台调用前台javascript的五种方法 由于项目需要,用到其他项目组用VC开发的组件,在web后台代码无法访问这个组件,所以只好通过后台调用前台的javascript,从而操作这个组件.在网上 ...
- 由ASP.NET所谓前台调用后台、后台调用前台想到HTTP——实践篇(二)
在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议内容,在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP—— ...
- 由ASP.NET所谓前台调用后台、后台调用前台想到HTTP
由ASP.NET所谓前台调用后台.后台调用前台想到HTTP 在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议内容,在由 ...
- ASP.NET所谓前台调用后台、后台调用前台想到HTTP——实践篇
由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——实践篇 在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议 ...
随机推荐
- kettle工具同步数据乱码-Linux下乱码问题二
将写好的kettle工程部署到Linux下后,同步的数据都成了乱码,幸运的是数据库有备份. 下面就说一下,kettle工程如何同步两端编码格式都是utf8的数据库. 我们只需要更改kettle数据库连 ...
- 使用java连接hive,并执行hive语句详解
安装hadoop 和 hive我就不多说了,网上太多文章 自己看去 首先,在机器上打开hiveservice hive --service hiveserver -p 50000 & 打开50 ...
- 通过ant脚本编译打包android工程
通过ant脚本,编译打包android工程 1.Android程序编译.打包.签名.发布的三种方式: 方式一:命令行手动编译打包 方式二:使用ant自动编译打包 方式三:使用eclipse+AD ...
- Starting httpd:Could not reliably determine the server's fully qualified domain name
#service httpd start #Starting httpd: httpd: Could not reliably determine the server's fully qualifi ...
- LDAP实例异常停止日志提示虚拟内存virtual memory不足
[05/Oct/2014:20:50:37 +0800] - ERROR<5135> - Resource Limit - conn=-1 op=-1 msgId=-1 - Memory ...
- 登录DSCCC控制台报错提示:安装错误代码: 3
登录DSCCC控制台报错内容:读取安装配置时出错 检查目录服务控制中心状态时出现意外错误. 显示详细资料 隐藏详细资料 安装错误代码: 3 堆栈: com.sun.directory.common.s ...
- 【巧妙算法系列】【UVA 11384】 Help is needed for Dexter 正整数序列
Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee ...
- php安装扩展模块(curl模块)
php安装扩展模块的思路: 1,首先找到需要安装的扩展模块的目录.一般在/usr/local/php/ext目录下 但是有的模块php源码中不一定有,需要自己下载比如memcache.redis等. ...
- 解决linux top命令提示的unknown terminal type的问题
[root@localhost bin]# top 'xterm-256color': unknown terminal type. 在网上搜索了解决方法如下: 解决办法: 1.临时办法,下次启动失效 ...
- vim自动补全文章搜集
引用文章A:http://blog.csdn.net/wendy260310/article/details/18035555 文章介绍:添加C++标准库的tags文件方法.(中文版) 引用文章B:h ...