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协议 ...
随机推荐
- IOS 从Resource文件夹下Copy文件到沙盒
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.t ...
- 【贪心+中位数】【新生赛3 1007题】 Problem G (K)
Problem G Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- android XML解析之DOM解析方式
DOM 解析方式步骤: 第一步:首选需要获得DOM解析器工厂实例 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ...
- 《JavaScript 闯关记》之对象
对象是 JavaScript 的数据类型.它将很多值(原始值或者其他对象)聚合在一起,可通过名字访问这些值,因此我们可以把它看成是从字符串到值的映射.对象是动态的,可以随时新增和删除自有属性.对象除了 ...
- mvc 微软票据验证
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- WindowsForm 打印
打印: 打印对话框:printdialog 页面设置:pagesetupdialog 这两个对话框都需要通过设置printdocument来指定打印对象 printdocument:打印对象,必须要有 ...
- 使用mysqlbinlog工具进行基于位置或时间点的数据恢复
使用mysqlbinlog工具进行基于位置或时间点的恢复 MySQL备份一般采取全备份加日志备份的方式,比如每天执行一次全备份,每小时执行一次二进制日志备份.这样在MySQL Server故障后可以使 ...
- php 格式化金额
/** * 格式化金额 * * @param int $money * @param int $len * @param string $sign * @return string */ functi ...
- Python中yield深入理解
众所周知,python中的yield有这样的用法: def test(alist): for i in alist: yield i 这样,这个test函数就变成了一个生成器,当每次调用的时候,就会自 ...
- 验证角谷猜想(hd1279)
验证角谷猜想 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...