功能很强大的UI封装类

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;
using  System.Drawing;
using  System.Text;
using  System.IO;
using  System.Threading;
namespace  WebHelper.UI
{
    
/// <summary>
    
/// Summary description for UIHelper
    
/// </summary>

    public static class UIHelper
    
{
        
Static Property Get BaseUrl(静态属性获取URL地址)

        
Alert()

        
ScrollMessage

        
Redirect()

        
AddConfirm

        
AddShowDialog

        
AddShowDialog

        
AddShowDialog
        
ClearTextBox

        
OpenWindow

        
ShowDialog

        
CloseWindows

        
ShowStatusBar

        
Image水印

        
PlayMediaFile

        
ShowProgBar

        
fixedHeader

        
refreshPage

        
Page_revealTrans

        
/**/
        
/// <summary>
        
/// 显示一段自定义的输出代码
        
/// </summary>
        
/// <param name="page">页面指针,一般为This</param>

        public static void ResponseScript(System.Web.UI.Page page, string script)
        
{
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(script.Trim());
            sb.Append(
"</script>");
            page.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 调用客户端JavaScript函数
        
/// </summary>
        
/// <param name="page">页面指针,一般为This</param>
        
/// <param name="scriptName">函数名,带参数,如:FunA(1);</param>

        public static void CallClientScript(System.Web.UI.Page page, string scriptName)
        
{
            String csname 
= "PopupScript";
            Type cstype 
= page.GetType();
            System.Web.UI.ClientScriptManager cs 
= page.ClientScript;
            
if (!cs.IsStartupScriptRegistered(cstype, csname))
            
{
                String cstext 
= scriptName;
                cs.RegisterStartupScript(cstype, csname, cstext, 
true);
            }

        }


        
/// <summary>
        
/// 弹出对话框(弹出对话框后css会失效)
        
/// </summary>
        
/// <param name="message">提示信息</param>

        public static void ShowMessage(string message)
        
{
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(
"alert(\"" + message.Trim() + "\"); \n");
            sb.Append(
"</script>");

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 弹出对话框(不影响css样式)
        
/// </summary>
        
/// <param name="page">页面指针,一般为this</param>
        
/// <param name="scriptKey">脚本键,唯一</param>
        
/// <param name="message">提示信息</param>

        public static void ShowMessage(System.Web.UI.Page page, string scriptKey, string message)
        
{
            System.Web.UI.ClientScriptManager csm 
= page.ClientScript;
            
if (!csm.IsClientScriptBlockRegistered(scriptKey))
            
{
                
string strScript = "alert('" + message + "');";
                csm.RegisterClientScriptBlock(page.GetType(), scriptKey, strScript, 
true);
            }

        }


        
/// <summary>
        
/// 为控件添加确认提示对话框
        
/// </summary>
        
/// <param name="Control">需要添加提示的对话框</param>
        
/// <param name="message">提示信息</param>

        public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string message)
        
{
            Control.Attributes.Add(
"onclick""return confirm('" + message + "');");
        }


        
/**/
        
/// <summary>
        
/// 显示一个弹出窗口,并转向目标页(导航)
        
/// </summary>

        public static void ShowAndRedirect(string message, string url)
        
{
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(
"alert(\"" + message.Trim() + "\"); \n");
            sb.Append(
"window.location.href=\"" + url.Trim().Replace("'", "") + "\";\n");
            sb.Append("</script>");

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 显示一个弹出窗口,重新加载当前页
        
/// </summary>

        public static void ShowAndReLoad(string message)
        
{
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(
"alert(\"" + message.Trim() + "\"); \n");
            sb.Append(
"window.location.href=window.location.href;\n");
            sb.Append(
"</script>");

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 显示一个弹出窗口,刷新当前页(危险的,有可能陷入死循环)
        
/// </summary>

        public static void ShowAndRefresh(string message)
        
{
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(
"alert(\"" + message.Trim() + "\"); \n");
            sb.Append(
"document.execCommand('Refresh')");
            sb.Append(
"</script>");

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 显示一个弹出窗口,并关闭当前页
        
/// </summary>
        
/// <param name="message"></param>

        public static void ShowAndClose(string message)
        
{
            System.Text.StringBuilder sb 
= new System.Text.StringBuilder();
            sb.Append(
"<script language=\"javascript\">\n");
            sb.Append(
"alert(\"" + message.Trim() + "\"); \n");
            sb.Append(
"window.close();\n");
            sb.Append(
"</script>\n");
            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 显示一个弹出窗口,并转向上一页
        
/// </summary>
        
/// <param name="message"></param>

        public static void ShowPre(string message)
        
{
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(
"alert(\"" + message.Trim() + "\"); \n");
            sb.Append(
"var p=document.referrer; \n");
            sb.Append(
"window.location.href=p;\n");
            sb.Append(
"</script>");

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 页面重载
        
/// </summary>

        public static void ReLoad()
        
{
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(
"window.location.href=window.location.href;");
            sb.Append(
"</script>");
            System.Web.HttpContext.Current.Response.Write(sb.ToString());

        }


        
/// <summary>
        
/// 重定向
        
/// </summary>

        public static void Redirect(string url)
        
{
            
//string path = "http://" + System.Web.HttpContext.Current.Request.Url.Host + ":" + System.Web.HttpContext.Current.Request.Url.Port + url;
            string path = "http://" + System.Web.HttpContext.Current.Request.Url.Host + url;
            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language=\"javascript\"> \n");
            sb.Append(
string.Format("window.location.href='{0}';", @path.Replace("'""")));
            sb.Append(
"</script>");

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }

    }

}

Trackback:http://www.cnblogs.com/chu888chu888/archive/2008/02/03/1063266.html

你可能感兴趣的:(UI)