/// <summary>
/// 脚本工具类
/// </summary>
public class ScriptUtility : System.Web.UI.Page
{
/// <summary>
/// 显示提示信息
/// </summary>
/// <param name="message">提示信息</param>
/// <param name="goBack">是否返回前一页</param>
/// <param name="isRefresh">是否刷新本页</param>
/// <param name="jumpUrl">跳转页面(为空则不跳转)</param>
public static void Alert(string message, bool goBack, bool isRefresh, string jumpUrl)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language='javascript'>alert('" + message.Replace("'", "\'") + "');");
if (goBack)
{
sb.Append("history.back();");
}
else if (isRefresh)
{
sb.Append("location.href=location.href;");
}
else
{
if (!string.IsNullOrEmpty(jumpUrl))
{
sb.Append("location.href='" + jumpUrl + "';");
}
}
sb.Append("</script>");
HttpContext.Current.Response.Write(sb.ToString());
}
/// <summary>
/// 返回前一页
/// </summary>
public static void GoBack()
{
string str = "<script language='javascript'>history.back();</script>";
HttpContext.Current.Response.Write(str);
}
/// <summary>
/// 刷新当前页面
/// </summary>
public static void Refresh()
{
string str = "<script language='javascript'>location.href=location.href;</script>";
HttpContext.Current.Response.Write(str);
}
/// <summary>
/// 刷新父窗体,关闭当前窗体
/// </summary>
public static void RefreshParent()
{
string str = "<script language='javascript'>RefreshParent();WinClose();</script>";
HttpContext.Current.Response.Write(str);
}
/// <summary>
/// 刷新父窗体和子窗体
/// </summary>
public static void RefreshAll()
{
string str = "<script language='javascript'>RefreshParent();location.href=location.href;</script>";
HttpContext.Current.Response.Write(str);
}
/// <summary>
/// 关闭当前页面
/// </summary>
public static void WinClose()
{
string str = "<script language='javascript'>WinClose();</script>";
HttpContext.Current.Response.Write(str);
}
/// <summary>
/// 跳转页面
/// </summary>
/// <param name="url">重定向页面</param>
public static void Jump(string url)
{
if (!string.IsNullOrEmpty(url))
{
string str = "<script language='javascript'>location.href='" + url + "';</script>";
HttpContext.Current.Response.Write(str);
}
}
/// <summary>
/// 跳转页面
/// </summary>
/// <param name="url">重定向页面</param>
/// <param name="target">目标框架</param>
public static void Jump(string url, string target)
{
if (!string.IsNullOrEmpty(target))
{
string str = "<script language='javascript'>" + target + ".href='" + url + "';</script>";
HttpContext.Current.Response.Write(str);
}
else
{
Jump(url);
}
}
}
/// <summary>
/// 页面工具类
/// </summary>
public class PageUtility
{
/// <summary>
/// 地址栏取值
/// </summary>
/// <param name="name">参数名</param>
/// <returns></returns>
public static string GetQueryValue(string name)
{
string str = string.Empty;
if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[name]))
{
str = HttpContext.Current.Request.QueryString[name];
str = str.Replace("'", "");
str = str.Replace("--", "");
str = str.Trim();
}
return str;
}
/// <summary>
/// 表单取值
/// </summary>
/// <param name="name">表单元素</param>
/// <returns></returns>
public static string GetFormValue(string name)
{
string str = string.Empty;
if (!string.IsNullOrEmpty(HttpContext.Current.Request.Form[name]))
{
str = HttpContext.Current.Request.Form[name];
str = str.Replace("'", "");
str = str.Replace("--", "");
str = str.Trim();
}
return str;
}
}