asp.net弹出窗口操作类
2013-07-16 20:42
120 查看
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <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>"); } }转自:http://hi.baidu.com/jordan51341/item/615c373a246f5bfddf2221a4
另一个类见:http://xinyaoxp.blog.163.com/blog/static/3467734920088510322113/
相关文章推荐
- ASP.NET中让网页弹出窗口不再困难
- 弹出窗口汇总asp.net
- ASP.NET之精通弹出窗口
- Asp.net 中弹出窗口
- 精通ASP.NET中弹出窗口技术
- Asp.net弹出新窗口,获得返回值
- asp.net弹出窗口 返回值
- Asp.net弹出新窗口,在gridview 获取值并返回值
- ASP.NET之精通弹出窗口
- Asp.net关闭弹出窗口刷新父窗口
- popupWin 属性及用法介绍 ASP.NET控件,仿QQ,msn右下角弹出窗口
- ASP.NET实现自适应图片大小的弹出窗口(窗口可任意编辑)
- [原创] ASP.NET 中如何弹出提示窗口然后导向另外一个页面
- ASP.net 让窗口WEB打开后,弹出一个选择窗口供应选择,注意Page_Load顺序,JS产生的找不到对象的问题
- ASP.NET 仿MSN Messenger Alert的弹出窗口控件
- ASP.NET实现自适应图片大小的弹出窗口(窗口可任意编辑)
- CRM2011弹出asp.net模态窗口关闭的问题
- Asp.Net中用javascript实现弹出窗口永远居中
- (精)在ASP.NET中使用IFRAME+DIV,可以实现在同一页面使用弹出(模态)窗口
- ASP.net 仿QQ弹出窗口