using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace HD.Helper.Common
{
///
/// JavaScript客户端脚本输出帮助类
///
public class JavaScriptHelper
{
#region 弹出信息,并跳转指定页面
///
/// 弹出信息,并跳转指定页面。
///
public static void AlertAndRedirect(string message, string toURL)
{
string js = "";
HttpContext.Current.Response.Write(string.Format(js, message, toURL));
HttpContext.Current.Response.End();
}
#endregion
#region 弹出信息,并返回历史页面
///
/// 弹出信息,并返回历史页面
///
public static void AlertAndGoHistory(string message, int value)
{
string js = @"";
HttpContext.Current.Response.Write(string.Format(js, message, value));
HttpContext.Current.Response.End();
}
#endregion
#region 弹出信息 并指定到父窗口
///
/// 弹出信息 并指定到父窗口
///
public static void AlertAndParentUrl(string message, string toURL)
{
string js = "";
HttpContext.Current.Response.Write(string.Format(js, message, toURL));
}
#endregion
#region 返回到父窗口
///
/// 返回到父窗口
///
public static void ParentRedirect(string ToUrl)
{
string js = "";
HttpContext.Current.Response.Write(string.Format(js, ToUrl));
}
#endregion
#region 弹出信息
///
/// 弹出信息
///
public static void Alert(string message)
{
string js = "";
HttpContext.Current.Response.Write(string.Format(js, message));
}
#endregion
#region 注册脚本块
///
/// 注册脚本块
///
public static void RegisterScriptBlock(System.Web.UI.Page page, string _ScriptString)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "scriptblock", "");
}
#endregion
#region 显示模态窗口
///
/// 返回把指定链接地址显示模态窗口的脚本
///
///
///
///
///
///
public static string GetShowModalWindowScript(string wid, string title, int width, int height, string url)
{
return string.Format("setTimeout(\"showModalWindow('{0}','{1}',{2},{3},'{4}')\",100);", wid, title, width, height, url);
}
///
/// 把指定链接地址显示模态窗口
///
/// 窗口ID
/// 标题
/// 宽度
/// 高度
/// 链接地址
public static void ShowModalWindow(string wid, string title, int width, int height, string url)
{
WriteScript(GetShowModalWindowScript(wid, title, width, height, url));
}
///
/// 为指定控件绑定前台脚本:显示模态窗口
///
///
///
///
///
///
///
///
///
public static void ShowCilentModalWindow(string wid, WebControl control, string eventName, string title, int width, int height, string url, bool isScriptEnd)
{
string script = isScriptEnd ? "return false;" : "";
control.Attributes[eventName] = string.Format("showModalWindow('{0}','{1}',{2},{3},'{4}');" + script, wid, title, width, height, url);
}
///
/// 为指定控件绑定前台脚本:显示模态窗口
///
///
///
///
///
///
///
///
///
public static void ShowCilentModalWindow(string wid, TableCell cell, string eventName, string title, int width, int height, string url, bool isScriptEnd)
{
string script = isScriptEnd ? "return false;" : "";
cell.Attributes[eventName] = string.Format("showModalWindow('{0}','{1}',{2},{3},'{4}');" + script, wid, title, width, height, url);
}
#endregion
#region 显示客户端确认窗口
///
/// 显示客户端确认窗口
///
///
///
///
public static void ShowCilentConfirm(WebControl control, string eventName, string message)
{
ShowCilentConfirm(control, eventName, "系统提示", 210, 125, message);
}
///
/// 显示客户端确认窗口
///
///
///
///
///
///
///
public static void ShowCilentConfirm(WebControl control, string eventName, string title, int width, int height, string message)
{
control.Attributes[eventName] = string.Format("return showConfirm('{0}',{1},{2},'{3}','{4}');", title, width, height, message, control.ClientID);
}
#endregion
#region 写javascript脚本
///
/// 写javascript脚本
///
/// 脚本内容
public static void WriteScript(string script)
{
Page page = GetCurrentPage();
page.ClientScript.RegisterStartupScript(
page.GetType(),
System.Guid.NewGuid().ToString(),
script,
true);
}
///
/// 得到当前页对象实例
///
///
public static Page GetCurrentPage()
{
return (Page)HttpContext.Current.Handler;
}
#endregion
#region 回到历史页面
///
/// 回到历史页面
///
/// -1/1
public static void GoHistory(int value)
{
#region
string js = @"";
HttpContext.Current.Response.Write(string.Format(js, value));
HttpContext.Current.Response.End();
#endregion
}
#endregion
#region 关闭当前窗口
///
/// 关闭当前窗口
///
public static void CloseWindow()
{
#region
string js = @"";
HttpContext.Current.Response.Write(js);
HttpContext.Current.Response.End();
#endregion
}
#endregion
#region 刷新父窗口
///
/// 刷新父窗口
///
public static void RefreshParent(string url)
{
#region
string js = @"";
HttpContext.Current.Response.Write(js);
#endregion
}
#endregion
#region 刷新打开窗口
///
/// 刷新打开窗口
///
public static void RefreshOpener()
{
#region
string js = @"";
HttpContext.Current.Response.Write(js);
#endregion
}
#endregion
#region 转向Url指定的页面
///
/// 转向Url指定的页面
///
/// 连接地址
public static void JavaScriptLocationHref(string url)
{
#region
string js = @"";
js = string.Format(js, url);
HttpContext.Current.Response.Write(js);
#endregion
}
#endregion
#region 打开指定大小位置的模式对话框
///
/// 打开指定大小位置的模式对话框
///
/// 连接地址
/// 宽
/// 高
/// 距离上位置
/// 距离左位置
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
}
#endregion
#region 打开模式对话框
///
/// 打开模式对话框
///
/// 链接地址
///
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 = @"";
return js;
#endregion
}
#endregion
#region 打开指定大小的新窗体
///
/// 打开指定大小的新窗体
///
/// 地址
/// 宽
/// 高
/// 头位置
/// 左位置
public static void OpenWebFormSize(string url, int width, int heigth, int top, int left)
{
#region
string js = @"";
HttpContext.Current.Response.Write(js);
#endregion
}
#endregion
#region 页面跳转(跳出框架)
///
/// 页面跳转(跳出框架)
///
///
public static void JavaScriptExitIfream(string url)
{
string js = @"";
js = string.Format(js, url);
HttpContext.Current.Response.Write(js);
}
#endregion
}
}