zoukankan      html  css  js  c++  java
  • ASP.NET 弹出窗口

    //ASP.NET 弹出窗口

    //来源:http://hi.baidu.com/jordan51341/blog/item/1ab4f9ca8bba1243f21fe7da.html
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <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.create_rElement('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.a(bgObj); ");
                Builder.AppendLine("var msgObj=document.create_rElement('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.create_rElement('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.getElementByIdx_x('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
                Builder.AppendLine("document.body.a(msgObj); ");
                Builder.AppendLine("document.getElementByIdx_x('msgDiv').a(title);");
                Builder.AppendLine("var txt=document.create_rElement('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.getElementByIdx_x('msgDiv').a(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.create_rElement('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.a(bgObj); ");
                Builder.AppendLine("var msgObj=document.create_rElement('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.create_rElement('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.getElementByIdx_x('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
                Builder.AppendLine("document.body.a(msgObj); ");
                Builder.AppendLine("document.getElementByIdx_x('msgDiv').a(title);");
                Builder.AppendLine("var txt=document.create_rElement('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.getElementByIdx_x('msgDiv').a(txt);return false;}");
                Builder.AppendLine(" ShowBDDialog(); </script>");
                page.Response.Write(Builder.ToString());
                page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javscript'>ShowBDDialog();</" + "script>");
            }
        }
  • 相关阅读:
    POJ 2236 Wireless Network(并查集)
    POJ 2010 Moo University
    POJ 3614 Sunscreen(贪心,区间单点匹配)
    POJ 2184 Cow Exhibition(背包)
    POJ 1631 Bridging signals(LIS的等价表述)
    POJ 3181 Dollar Dayz(递推,两个long long)
    POJ 3046 Ant Counting(递推,和号优化)
    POJ 3280 Cheapest Palindrome(区间dp)
    POJ 3616 Milking Time(dp)
    POJ 2385 Apple Catching(01背包)
  • 原文地址:https://www.cnblogs.com/kevinkim/p/2298884.html
Copyright © 2011-2022 走看看