Asp.net封装js的类
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI; /// </summary>
public class JScript
{
#region 旧版本
/// <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
} /// <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 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);
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
}
/// <summary>
/// 弹出模态窗口
/// </summary>
/// <param name="webFormUrl"></param>
/// <param name="features"></param>
public static void ShowModalDialogWindow(string webFormUrl, string features)
{
string js = ShowModalDialogJavascript(webFormUrl, features);
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 弹出模态窗口
/// </summary>
/// <param name="webFormUrl"></param>
/// <param name="features"></param>
/// <returns></returns>
public static string ShowModalDialogJavascript(string webFormUrl, string features)
{
#region
string js = @"<script language=javascript>
showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
return js;
#endregion
}
#endregion #region 新版本
/// <summary>
/// 弹出JavaScript小窗口
/// </summary>
/// <param name="js">窗口信息</param>
public static void Alert(string message, Page page)
{
#region
string js = @"<Script language='JavaScript'>
alert('" + message + "');</Script>";
//HttpContext.Current.Response.Write(js);
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "alert"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "alert", js);
}
#endregion
} /// <summary>
/// 弹出消息框并且转向到新的URL
/// </summary>
/// <param name="message">消息内容</param>
/// <param name="toURL">连接地址</param>
public static void AlertAndRedirect(string message, string toURL, Page page)
{
#region
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
//HttpContext.Current.Response.Write(string.Format(js, message, toURL));
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "AlertAndRedirect"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "AlertAndRedirect", string.Format(js, message, toURL));
}
#endregion
} /// <summary>
/// 回到历史页面
/// </summary>
/// <param name="value">-1/1</param>
public static void GoHistory(int value, Page page)
{
#region
string js = @"<Script language='JavaScript'>
history.go({0});
</Script>";
//HttpContext.Current.Response.Write(string.Format(js, value));
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "GoHistory"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "GoHistory", 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, Page page)
{
#region
string js = @"<Script language='JavaScript'>
window.opener.location.href='" + url + "';window.close();</Script>";
//HttpContext.Current.Response.Write(js);
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshParent"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshParent", js);
}
#endregion
} /// <summary>
/// 刷新打开窗口
/// </summary>
public static void RefreshOpener(Page page)
{
#region
string js = @"<Script language='JavaScript'>
opener.location.reload();
</Script>";
//HttpContext.Current.Response.Write(js);
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshOpener"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshOpener", 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, Page page)
{
#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);
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "OpenWebFormSize"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "OpenWebFormSize", js);
}
#endregion
} /// <summary>
/// 转向Url制定的页面
/// </summary>
/// <param name="url">连接地址</param>
public static void JavaScriptLocationHref(string url, Page page)
{
#region
string js = @"<Script language='JavaScript'>
window.location.replace('{0}');
</Script>";
js = string.Format(js, url);
//HttpContext.Current.Response.Write(js);
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "JavaScriptLocationHref"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "JavaScriptLocationHref", 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, Page page)
{
#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, page);
#endregion
}
/// <summary>
/// 弹出模态窗口
/// </summary>
/// <param name="webFormUrl"></param>
/// <param name="features"></param>
public static void ShowModalDialogWindow(string webFormUrl, string features, Page page)
{
string js = ShowModalDialogJavascript(webFormUrl, features);
//HttpContext.Current.Response.Write(js);
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "ShowModalDialogWindow"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "ShowModalDialogWindow", js);
}
}
// /// <summary>
// /// 弹出模态窗口
// /// </summary>
// /// <param name="webFormUrl"></param>
// /// <param name="features"></param>
// /// <returns></returns>
// public static string ShowModalDialogJavascript(string webFormUrl, string features)
// {
// #region
// string js = @"<script language=javascript>
// showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
// return js;
// #endregion
// }
#endregion
} /// <summary>
/// 一些常用的Js调用
/// 添加新版说明:由于旧版普遍采用Response.Write(string msg)的方式输出js脚本,这种
/// 方式输出的js脚本会在html元素的<html></html>标签之外,破坏了整个xhtml的结构,
/// 而新版本则采用ClientScript.RegisterStartupScript(string msg)的方式输出,不会改变xhtml的结构,
/// 不会影响执行效果。
/// 为了向下兼容,所以新版本采用了重载的方式,新版本中要求一个System.Web.UI.Page类的实例。
代码
using System.Web;
/// <summary>
/// Javascript常用方法
/// </summary>
public class JS
{
private static string ScriptStart = "<script type=\"text/javascript\">";
private static string ScriptEnd = "</script>"; /// <summary>
/// 写入JS脚本内容
/// </summary>
/// <param name="ScriptString">脚本内容</param>
/// <param name="IsResponseEnd">是否中断服务端脚本执行</param>
public static void WriteScript(string ScriptString, bool IsResponseEnd)
{
HttpContext.Current.Response.Write(ScriptStart);
HttpContext.Current.Response.Write(ScriptString);
HttpContext.Current.Response.Write(ScriptEnd);
if (IsResponseEnd)
{
HttpContext.Current.Response.End();
}
} /// <summary>
/// 弹出警告框
/// </summary>
/// <param name="AlertMessage">提示信息</param>
/// <param name="IsResponseEnd">是否中断服务端脚本执行</param>
public static void Alert(string AlertMessage, bool IsResponseEnd)
{
HttpContext.Current.Response.Write(ScriptStart);
HttpContext.Current.Response.Write("alert('" + AlertMessage + "');history.back();");
HttpContext.Current.Response.Write(ScriptEnd);
if (IsResponseEnd)
{
HttpContext.Current.Response.End();
}
} /// <summary>
/// 弹出警告框并跳转
/// </summary>
/// <param name="AlertMessage">提示信息</param>
/// <param name="RedirectPath">跳转路径</param>
/// <param name="IsTopWindow">是否为全屏跳转</param>
public static void Alert(string AlertMessage, string RedirectPath, bool IsTopWindow)
{
HttpContext.Current.Response.Write(ScriptStart);
HttpContext.Current.Response.Write("alert('" + AlertMessage + "');");
if (IsTopWindow)
{
HttpContext.Current.Response.Write("parent.top.location.href='" + RedirectPath + "';");
}
else
{
HttpContext.Current.Response.Write("location.href='" + RedirectPath + "';");
}
HttpContext.Current.Response.Write(ScriptEnd);
HttpContext.Current.Response.End();
} /// <summary>
/// 弹出警告框并关闭窗口
/// </summary>
/// <param name="AlertMessage">提示信息</param>
public static void AlertAndClose(string AlertMessage)
{
HttpContext.Current.Response.Write(ScriptStart);
HttpContext.Current.Response.Write("alert('" + AlertMessage + "');window.close();");
HttpContext.Current.Response.Write(ScriptEnd);
HttpContext.Current.Response.End();
} /// <summary>
/// 全屏跳转
/// </summary>
/// <param name="RedirectpPath">跳转路径</param>
public static void TopRedirect(string RedirectpPath)
{
HttpContext.Current.Response.Write(ScriptStart);
HttpContext.Current.Response.Write("parent.top.location.href='" + RedirectpPath + "';");
HttpContext.Current.Response.Write(ScriptEnd);
HttpContext.Current.Response.End();
} /// <summary>
/// 判断并跳转
/// </summary>
/// <param name="confirmMessage">提示信息</param>
/// <param name="YesRedirectPath">选择“是”后跳转的路径</param>
/// <param name="NoRedirectPath">选择“否”后跳转的路径</param>
/// <param name="IsResponseEnd">是否中断服务端脚本执行</param>
public static void ConfirmRedirect(string confirmMessage, string YesRedirectPath, string NoRedirectPath, bool IsResponseEnd)
{
HttpContext.Current.Response.Write(ScriptStart);
HttpContext.Current.Response.Write("if(confirm('" + confirmMessage + "')){location.href='" + YesRedirectPath + "';}else{location.href='" + NoRedirectPath + "';}");
HttpContext.Current.Response.Write(ScriptEnd);
if (IsResponseEnd)
{
HttpContext.Current.Response.End();
}
} /// <summary>
/// 判断并写入脚本代码
/// </summary>
/// <param name="confirmMessage">提示信息</param>
/// <param name="YesScript">选择“是”后写入的脚本内容</param>
/// <param name="NoScript">选择“否”后写入的脚本内容</param>
/// <param name="IsResponseEnd">是否中断服务端脚本执行</param>
public static void ConfirmScript(string confirmMessage, string YesScript, string NoScript, bool IsResponseEnd)
{
HttpContext.Current.Response.Write(ScriptStart);
HttpContext.Current.Response.Write("if(confirm('" + confirmMessage + "')){" + YesScript + "}else{" + NoScript + "}");
HttpContext.Current.Response.Write(ScriptEnd);
if (IsResponseEnd)
{
HttpContext.Current.Response.End();
}
} }
代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls; namespace WebApplication3
{ /// <summary>
/// javascript弹出窗口封装类
/// </summary>
public static class JSCommon
{
/// <summary>
/// 显示消息提示对话框
/// </summary>
/// <param name="page">当前页面指针,一般为"this"</param>
/// <param name="msg">提示信息</param>
public static void ShowAlert(System.Web.UI.Page page, string msg)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');", msg);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 打开大小不可变模式窗口
/// </summary>
/// <param name="page">当前页面指针,一般为"this"</param>
/// <param name="PageUrl">打开的模式窗口显示的网页地址</param>
/// <param name="Width">打开的模式窗口的宽度</param>
/// <param name="Height">打开的模式窗口的高度</param>
public static void OpenFixModalDialog(System.Web.UI.Page page, String PageUrl, int Width, int Height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("window.showModalDialog('{0}',null,'dialogWidth:{1}px;dialogHeight:{2}px;help:no;unadorned:no;resizable:no;status:no');", PageUrl, Width, Height);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 打开大小可变模式窗口
/// </summary>
/// <param name="page">当前页面指针,一般为"this"</param>
/// <param name="PageUrl">打开的模式窗口显示的网页地址</param>
/// <param name="Width">打开的模式窗口的宽度</param>
/// <param name="Height">打开的模式窗口的高度</param>
public static void OpenSizeableModalDialog(System.Web.UI.Page page, String PageUrl, int Width, int Height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("window.showModalDialog('{0}',null,'dialogWidth:{1}px;dialogHeight:{2}px;help:no;unadorned:no;resizable:yes;status:no');", PageUrl, Width, Height);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 打开悬浮提示窗口
/// </summary>
/// <param name="page">页面指针 一般输入"this"</param>
/// <param name="message">显示的消息</param>
/// <param name="Width">窗口宽度</param>
/// <param name="height">窗口高度</param>
public static void OpenFloatDialog(System.Web.UI.Page page, string message, int Width, int height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script type='text/javascript' language='javascript' defer>");
// Builder.Append("var msgw,msgh,bordercolor; ");
Builder.AppendLine("function ShowBDDialog(){ ");
Builder.AppendLine("bordercolor='#66ccff';titlecolor='#99CCFF';");
Builder.AppendLine("var sWidth,sHeight; sWidth=document.body.offsetWidth; sHeight=document.body.offsetHeight;");
Builder.AppendLine("var bgObj=document.createElement('div'); ");
Builder.AppendLine(" bgObj.setAttribute('id','bgDiv'); ");
Builder.AppendLine("bgObj.style.position='absolute'; ");
Builder.AppendLine("bgObj.style.top='0'; bgObj.style.background='#dcdcdc';");
Builder.AppendLine("bgObj.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75';");
Builder.AppendLine("bgObj.style.opacity='0.6'; ");
Builder.AppendLine("bgObj.style.left='0';");
Builder.AppendLine("bgObj.style.width=sWidth + 'px'; ");
Builder.AppendLine("bgObj.style.height=sHeight + 'px';");
Builder.AppendLine("document.body.appendChild(bgObj); ");
Builder.AppendLine("var msgObj=document.createElement('div')");
Builder.AppendLine("msgObj.setAttribute('id','msgDiv');");
Builder.AppendLine("msgObj.setAttribute('align','center');");
Builder.AppendLine("msgObj.style.position='absolute';msgObj.style.background='white'; ");
Builder.AppendLine("msgObj.style.font='12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif';");
Builder.AppendLine("msgObj.style.border='1px solid ' + bordercolor;");
Builder.AppendFormat("msgObj.style.width='{0} '+ 'px'; ", Width);
Builder.AppendFormat("msgObj.style.height='{0}' + 'px';", height);
Builder.AppendFormat("msgObj.style.top=(document.documentElement.scrollTop + (sHeight-'{0}')/2) + 'px';", height);
Builder.AppendFormat("msgObj.style.left=(sWidth-'{0}')/2 + 'px';", Width);
Builder.AppendLine("var title=document.createElement('h4');");
Builder.AppendLine("title.setAttribute('id','msgTitle');");
Builder.AppendLine("title.setAttribute('align','right');");
Builder.AppendLine("title.style.margin='0'; ");
Builder.AppendLine("title.style.padding='3px'; title.style.background=bordercolor; ");
Builder.AppendLine("title.style.filter='progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);'; ");
Builder.AppendLine("title.style.opacity='0.75'; ");
Builder.AppendLine("title.style.border='1px solid ' + bordercolor;title.innerHTML='<a style=font-size:small href=#>关闭</a>'; ");
Builder.AppendLine("title.onclick=function(){ document.body.removeChild(bgObj);document.getElementById('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
Builder.AppendLine("document.body.appendChild(msgObj); ");
Builder.AppendLine("document.getElementById('msgDiv').appendChild(title);");
Builder.AppendLine("var txt=document.createElement('p');");
Builder.AppendFormat("txt.style.height='{0}';", height);
Builder.AppendFormat("txt.style.width='{0}';", Width);
Builder.AppendLine(" txt.style.margin='1em 0' ");
Builder.AppendLine("txt.setAttribute('id','msgTxt');");
Builder.AppendFormat("txt.innerHTML='{0}'; ", message);
Builder.AppendLine("document.getElementById('msgDiv').appendChild(txt);return false;}");
Builder.AppendLine(" ShowBDDialog(); </script>");
page.Response.Write(Builder.ToString());
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javscript'>ShowBDDialog();</" + "script>");
}
/// <summary>
/// 打开悬浮弹出窗口
/// </summary>
/// <param name="page">页面指针 一般输入"this"</param>
/// <param name="url">打开的页面的url</param>
/// <param name="Width">窗口宽度</param>
/// <param name="height">窗口高度</param>
public static void OpenFloatModalWindow(System.Web.UI.Page page, string url, int Width, int height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script type='text/javascript' language='javascript' defer>");
// Builder.Append("var msgw,msgh,bordercolor; ");
Builder.AppendLine("function ShowBDDialog(){ ");
Builder.AppendLine("bordercolor='#66ccff';titlecolor='#99CCFF';");
Builder.AppendLine("var sWidth,sHeight; sWidth=document.body.offsetWidth; sHeight=document.body.offsetHeight;");
Builder.AppendLine("var bgObj=document.createElement('div'); ");
Builder.AppendLine(" bgObj.setAttribute('id','bgDiv'); ");
Builder.AppendLine("bgObj.style.position='absolute'; ");
Builder.AppendLine("bgObj.style.top='0'; bgObj.style.background='#dcdcdc';");
Builder.AppendLine("bgObj.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75';");
Builder.AppendLine("bgObj.style.opacity='0.6'; ");
Builder.AppendLine("bgObj.style.left='0';");
Builder.AppendLine("bgObj.style.width=sWidth + 'px'; ");
Builder.AppendLine("bgObj.style.height=sHeight + 'px';");
Builder.AppendLine("document.body.appendChild(bgObj); ");
Builder.AppendLine("var msgObj=document.createElement('div')");
Builder.AppendLine("msgObj.setAttribute('id','msgDiv');");
Builder.AppendLine("msgObj.setAttribute('align','center');");
Builder.AppendLine("msgObj.style.position='absolute';msgObj.style.background='white'; ");
Builder.AppendLine("msgObj.style.font='12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif';");
Builder.AppendLine("msgObj.style.border='1px solid ' + bordercolor;");
Builder.AppendFormat("msgObj.style.width='{0} '+ 'px'; ", Width);
Builder.AppendFormat("msgObj.style.height='{0}' + 'px';", height);
Builder.AppendFormat("msgObj.style.top=(document.documentElement.scrollTop + (sHeight-'{0}')/2) + 'px';", height);
Builder.AppendFormat("msgObj.style.left=(sWidth-'{0}')/2 + 'px';", Width);
Builder.AppendLine("var title=document.createElement('h4');");
Builder.AppendLine("title.setAttribute('id','msgTitle');");
Builder.AppendLine("title.setAttribute('align','right');");
Builder.AppendLine("title.style.margin='0'; ");
Builder.AppendLine("title.style.padding='3px'; title.style.background=bordercolor; ");
Builder.AppendLine("title.style.filter='progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);'; ");
Builder.AppendLine("title.style.opacity='0.75'; ");
Builder.AppendLine("title.style.border='1px solid ' + bordercolor;title.innerHTML='<a style=font-size:small href=#>关闭</a>'; ");
Builder.AppendLine("title.onclick=function(){ document.body.removeChild(bgObj);document.getElementById('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
Builder.AppendLine("document.body.appendChild(msgObj); ");
Builder.AppendLine("document.getElementById('msgDiv').appendChild(title);");
Builder.AppendLine("var txt=document.createElement('iframe');");
Builder.AppendFormat("txt.style.height='{0}';", height);
Builder.AppendFormat("txt.style.width='{0}';", Width);
Builder.AppendLine(" txt.style.margin='1em 0' ");
Builder.AppendLine("txt.setAttribute('id','msgTxt');");
Builder.AppendFormat("txt.src='{0}'; ", url);
Builder.AppendLine("document.getElementById('msgDiv').appendChild(txt);return false;}");
Builder.AppendLine(" ShowBDDialog(); </script>");
page.Response.Write(Builder.ToString());
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javscript'>ShowBDDialog();</" + "script>");
}
}
}
代码
***********************************************************************************************
*【Author】:无意创新
*【Date】:2013年07月17日
*【URL】:http://www.cnblogs.com/getsound/archive/2010/09/01/1814833.html
*【Notice】:
*1、本文为原创技术文章,首发博客园个人站点。
*2、转载和引用请注明作者及出处。
*3、本文必须全文转载和引用,任何组织和个人未授权不能修改任何内容,并且未授权不可用于商业。
*4、本声明为文章一部分,转载和引用必须包括在原文中。
***********************************************************************************************
Asp.net封装js的类的更多相关文章
- js创建类(封装)
js如何创建类(封装) 学过其他面向对象语言的JavaScripter,可能都应用过类,如:class{},等定义的一系列方法, 但是初学者看是学习js的时候,经常会看到这样一句话,那就是Ja ...
- 原生Js封装的动画类
算法用的是Tween类,需要研究的参考这篇文章: http://www.cnblogs.com/cloudgamer/archive/2009/01/06/Tween.html 网页里常用的动画 放大 ...
- 分享非常好用的前端分页js工具类 灵活 简单易懂
分享自己封装的前端分页js工具类 下面是默认样式效果截图 可以随意更改js及css 很灵活 /** * pageSize, 每页显示数 * pageIndex, 当前页数 * pageCount 总 ...
- JS创建类的方法--简单易懂有实例
版权声明:本文为博主原创文章,转载请注明出处 Javascript是一种基于对象的语言,你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言,因为它的语法中没有Class. ...
- js构建类的方法
Javascript是一种基于对象的语言,你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言,因为它的语法中没有Class.(不过,ES6引入了Class这个概念,作为对 ...
- ASP.NET+d3.js实现Sqlserver数据库的可视化展示
效果: 数据库端: 前端展示: 实现原理: 1.在数据段建立两个存储过程 queryUserAnsawer(id) 根据用户ID返回每一题的得分,主要是bcp exe时不能直接在sqlserver中执 ...
- ASP.NET 的IP帮助类
个人网站地址: https://www.lesg.cn/netdaima/net/2016-239.html ASP.NET 的IP帮助类 在Web开发中会出现需要调用客户IP的方法: 一般调用方法就 ...
- .NET3.5中JSON用法以及封装JsonUtils工具类
.NET3.5中JSON用法以及封装JsonUtils工具类 我们讲到JSON的简单使用,现在我们来研究如何进行封装微软提供的JSON基类,达到更加方便.简单.强大且重用性高的效果. 首先创建一个类 ...
- MySQL数据库学习笔记(十一)----DAO设计模式实现数据库的增删改查(进一步封装JDBC工具类)
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
随机推荐
- ramips芯片,openwrt安装njit8021xclient
1.软件安装包 http://pan.baidu.com/s/1tcY2p 解压并通过winscp上传至路由器,利用putty进入控制台,依次输入以下4条命令,每次输入后点一次执行opkg insta ...
- quotation
1. 如果不能修心,则诸事繁杂!; 2. 人生,是该追求平淡长久,还是绚烂短暂,我想人人都有自己的答案,但阅历或者情感,都不是越多越好,烂桃三筐不如鲜杏一个,是古老的俗话,却至今鲜活有力.以量取胜,实 ...
- Chrome的Postman的使用
Chrome提供了一个很好的Web App 名为 Postman 使用这个web app,你可以输入一个url,然后可以很清楚的看到返回的各种结果 直接在Google中输入Postman, 找到它 ...
- CommandLine 和 Options
用到的jar包 <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli& ...
- powershell里添加对git的支持
在powershell命令行里依次运行 1. (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1 ...
- easyUI之tree
转自:http://www.cnblogs.com/CoreCaiNiao/archive/2010/08/20/1804387.html http://blog.csdn.net/l27775918 ...
- 多线程访问winform控件出现异常的解决方法
一. 多线程访问winform控件出现异常的解决方法 1. 问题描述<1> 如果创建某控件的线程之外的其他线程试图调用该控件,则会引发一个 InvalidOperationExcept ...
- PL/pgSQL学习笔记之一
开始 资料来源:http://www.postgresql.org/docs/9.1/static/plpgsql-overview.html 39.1 概要: PL/pgSQL是一种可载入的过程语言 ...
- BZOJ 2733: [HNOI2012]永无乡 启发式合并treap
2733: [HNOI2012]永无乡 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...