主题:C#输出JS代码封装类-Alart
/// <summary>
/// Alart 的摘要说明
/// </summary>
public class Alart
{
public enum AlartState
{
/// <summary>
/// 在根窗口中打开该连接
/// </summary>
OpenInTopWindow,
/// <summary>
/// 在父窗口中打开该连接
/// </summary>
OpenInParentWindow,
/// <summary>
/// 在当前窗口中打开该连接
/// </summary>
OpenInThisWindow,
/// <summary>
/// 返回到上一个页面
/// </summary>
Back,
/// <summary>
/// 关闭窗口
/// </summary>
CloseWindow,
/// <summary>
/// 不做任何操作
/// </summary>
Nothing
}
/// <summary>
/// 输出JS提示信息对话框
/// </summary>
/// <param name="context">页面Context</param>HttpContext.Current
/// <param name="msg">消息内容</param>
/// <param name="alartState">输出模式*枚举</param>
/// <param name="toUrl">提示后要转到的URL</param>
public static void ShowAlart(HttpContext context, string msg, AlartState alartState,string toUrl)
{
StringBuilder mySB = new StringBuilder();
mySB.AppendFormat("<script language='javascript'>alert('{0}');", msg);
switch (alartState)
{
case AlartState.Back:
mySB.Append("history.go(-1)");
break;
case AlartState.CloseWindow:
mySB.Append("top.window.close()");
break;
case AlartState.OpenInParentWindow:
mySB.AppendFormat("parent.location='{0}'",toUrl);
break;
case AlartState.OpenInThisWindow:
mySB.AppendFormat("window.locaiton='{0}'", toUrl);
break;
case AlartState.OpenInTopWindow:
mySB.AppendFormat("top.location='{0}'", toUrl);
break;
case AlartState.Nothing:
break;
}
mySB.Append("</script>");
context.Response.Write(mySB);
context.Response.End();
}
/// <summary>
/// 输出JS
/// </summary>
/// <param name="context">页面Context</param>HttpContext.Current
/// <param name="jsStr">脚本</param>
public static void UseJs(HttpContext context,string jsStr)
{
StringBuilder mySB = new StringBuilder();
mySB.AppendFormat("<script language='javascript'>{0}", jsStr);
mySB.Append("</script>");
context.Response.End();
}
}
(*^__^*) 嘻嘻……
请转载:[url=http://www.gobenet.net.cn]http://www.gobenet.net.cn[/url]
/// Alart 的摘要说明
/// </summary>
public class Alart
{
public enum AlartState
{
/// <summary>
/// 在根窗口中打开该连接
/// </summary>
OpenInTopWindow,
/// <summary>
/// 在父窗口中打开该连接
/// </summary>
OpenInParentWindow,
/// <summary>
/// 在当前窗口中打开该连接
/// </summary>
OpenInThisWindow,
/// <summary>
/// 返回到上一个页面
/// </summary>
Back,
/// <summary>
/// 关闭窗口
/// </summary>
CloseWindow,
/// <summary>
/// 不做任何操作
/// </summary>
Nothing
}
/// <summary>
/// 输出JS提示信息对话框
/// </summary>
/// <param name="context">页面Context</param>HttpContext.Current
/// <param name="msg">消息内容</param>
/// <param name="alartState">输出模式*枚举</param>
/// <param name="toUrl">提示后要转到的URL</param>
public static void ShowAlart(HttpContext context, string msg, AlartState alartState,string toUrl)
{
StringBuilder mySB = new StringBuilder();
mySB.AppendFormat("<script language='javascript'>alert('{0}');", msg);
switch (alartState)
{
case AlartState.Back:
mySB.Append("history.go(-1)");
break;
case AlartState.CloseWindow:
mySB.Append("top.window.close()");
break;
case AlartState.OpenInParentWindow:
mySB.AppendFormat("parent.location='{0}'",toUrl);
break;
case AlartState.OpenInThisWindow:
mySB.AppendFormat("window.locaiton='{0}'", toUrl);
break;
case AlartState.OpenInTopWindow:
mySB.AppendFormat("top.location='{0}'", toUrl);
break;
case AlartState.Nothing:
break;
}
mySB.Append("</script>");
context.Response.Write(mySB);
context.Response.End();
}
/// <summary>
/// 输出JS
/// </summary>
/// <param name="context">页面Context</param>HttpContext.Current
/// <param name="jsStr">脚本</param>
public static void UseJs(HttpContext context,string jsStr)
{
StringBuilder mySB = new StringBuilder();
mySB.AppendFormat("<script language='javascript'>{0}", jsStr);
mySB.Append("</script>");
context.Response.End();
}
}
(*^__^*) 嘻嘻……
请转载:[url=http://www.gobenet.net.cn]http://www.gobenet.net.cn[/url]