弹出窗口及转向url

代码
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.Text;

namespace  SDW.Common
{
    
///   <summary>
    
///  MessageObject 的摘要说明
    
///   </summary>
     public   class  MessageObject
    {
        
public  MessageObject()
        {
            
//
            
//  TODO: 在此处添加构造函数逻辑
            
//
        }

        
/// <summary>
        
/// 一般输出
        
/// </summary>
        
/// <para name="str"></para>
         public   static   void  Write( string  str)
        {
            System.Web.HttpContext.Current.Response.Write(str);
        }

        
/// <summary>
        
/// 显示一段自定义的输出代码
        
/// </summary>
        
/// <para name="myPage"></para>
        
/// <para name="strCode></para> "
         public   static   void  ShowJS(System.Web.UI.Page myPage,  string  strCode)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <sctipt language=\ " javascript\ "  > \n " );
            sb.Append(strCode.Trim());
            sb.Append(
" </script> " );
            myPage.Response.Write(sb);
        }

        
/// <summary>
        
/// 页面重载
        
/// </summary>
         public   static   void  Location()
        {
            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>
        
/// <para name="str"></para>
         public   static   void  ShowAlert( string  str)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <script language=\ " javascript\ " >\n " );
            sb.Append(
" alert(\ ""  + str.Trim() +  " \ " );\n " );
            sb.Append(
" </script>\n " );
            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }

        
/// <summary>
        
/// 显示一个新窗口,并关闭当前页
        
/// </summary>
        
/// <para name="str"></para>
         public   static   void  ShowClose( string  str)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <script language=\ " javascript\ " >\n " );
            sb.Append(
" alert(\ ""  + str.Trim() +  " \ " );\n " );
            sb.Append(
" window.close();\n " );
            sb.Append(
" </script>\n " );
            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }


        
/// <summary>
        
/// 显示一个新窗口,并关闭当前页,更新父页面
        
/// </summary>
        
/// <para name="str"></para>
         public   static   void  ShowCloseUpdate( string  str)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <script language=\ " javascript\ " >\n " );
            sb.Append(
" alert(\ ""  + str.Trim() +  " \ " );\n " );
            sb.Append(
" window.close();window.opener.location.reload();\n " );
            sb.Append(
" </script>\n " );
            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }

        
///   <summary>
        
///  显示一个弹出窗口,并转向当前页(刷新)
        
///   </summary>
        
///   <param name="str"></param>
         public   static   void  ShowLocation( string  str)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <script language=\ " javascript\ " > \n " );
            sb.Append(
" alert(\ ""  + str.Trim() +  " \ " ); \n " );
            sb.Append(
" window.location.href=window.location.href;\n " );
            sb.Append(
" </script> " );

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


        
///   <summary>
        
///  显示一个弹出窗口,并转向前页(刷新)
        
///   </summary>
        
///   <param name="str"></param>
         public   static   void  ShowPreLocation( string  str)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <script language=\ " javascript\ " > \n " );
            sb.Append(
" alert(\ ""  + str.Trim() +  " \ " ); \n " );
            sb.Append(
" window.close();window.opener.location.href=window.opener.location.href;\n " );
            sb.Append(
" </script> " );

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

        
///   <summary>
        
///  显示一个弹出窗口,并转向目标页(导航)
        
///   </summary>
        
///   <param name="str"></param>
        
///   <param name="url"></param>
         public   static   void  ShowRedirect( string  str,  string  url)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <script language=\ " javascript\ " > \n " );
            sb.Append(
" alert(\ ""  + str.Trim() +  " \ " ); \n " );
            sb.Append(
" window.location.href=\ ""  + url.Trim() +  " \ " ;\n " );
            sb.Append(
" </script> " );

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

        
///   <summary>
        
///  显示一个弹出窗口,并转向上一页
        
///   </summary>
        
///   <param name="str"></param>
         public   static   void  ShowPre( string  str)
        {
            StringBuilder sb 
=   new  StringBuilder();
            sb.Append(
" <script language=\ " javascript\ " > \n " );
            sb.Append(
" alert(\ ""  + str.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>
        
///   <param name="url"></param>
         public   static   void  RedirectPage( string  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));
            sb.Append(
" </script> " );

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
        }
    }
ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('success');", true);
}

 

你可能感兴趣的:(弹出窗口)