熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET打開新頁面而不關閉原來的頁面 實例代碼

2013-11-13 10:37:02  來源: .NET編程 
這篇文章介紹了ASPNET打開新頁面而不關閉原來的頁面 實例代碼有需要的朋友可以參考一下希望對你有所幫助   復制代碼 代碼如下:
ResposeWrite("<script     language=javascript>windowopen("+     url     +");</script>"); (打開簡潔窗口)
ResposeWrite("<script     language=javascript>windowopen("     +     url     +     "resizable=scrollbars=status=menubar=notoolbar=nolocation=no     menu=no);</script>");

  
ResponseRedirect("XXXaspx"true)——直接轉向新的頁面原窗口被代替;
ResponseWrite("<script>windowopen(XXXaspx_blank)</script>")——原窗口保留另外新增一個新頁面;
ResponseWrite("<script>windowlocation=XXXaspx</script>")——打開新的頁面原窗口被代替;
ServerTransfer("XXXaspx")——打開新的頁面;
ResponseWrite("<script>windowshowModelessDialog(XXXaspx)</script>")——原窗口保留以對話框形式打開新窗口;
ResponseWrite("<script>windowshowModelDialog(XXXaspx)</script>")——對話框形式打開新窗口原窗口被代替;
也可以自己寫方法

復制代碼 代碼如下:
public static void ShowMessage(SystemWebUIPage page string msg)
{
    pageClientScriptRegisterClientScriptBlock(pageGetType() "a" "alert(" + msgToString() + ");" true);
}

  
調用的時候
ShowMessage(this"要顯示的消息");
下面是整個類的代碼你可以挑著用

復制代碼 代碼如下:

  
using System;
using SystemCollectionsGeneric;
using SystemText;
namespace WorkLogic
{
    /// <summary>
    /// 顯示消息提示對話框
    /// </summary>
    public class MessageBox
    {
        private MessageBox()
        {
        }
        /// <summary>
        /// 顯示消息提示對話框
        /// </summary>
        /// <param name="page">當前頁面指針一般為this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowMessage(SystemWebUIPage page string msg)
        {
            //pageRegisterStartupScript("message" "alert(" + msgToString() + ");");
            pageClientScriptRegisterClientScriptBlock(pageGetType() "a" "alert(" + msgToString() + ");" true);
        }
        public static void ShowMessage(SystemWebUIUserControl control string msg)
        {
            controlPageClientScriptRegisterClientScriptBlock(controlPageGetType() "b" "alert(" + msgToString() + ");" true);
        }
        /// <summary>
        /// 控件點擊 消息確認提示框
        /// </summary>
        /// <param name="page">當前頁面指針一般為this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowConfirm(SystemWebUIWebControlsWebControl Control string msg)
        {
            //ControlAttributesAdd("onClick""if (!windowconfirm("+msg+")){return false;}");
            ControlAttributesAdd("onclick" "return confirm(" + msg + ");");
        }
        /// <summary>
        /// 顯示消息提示對話框並進行頁面跳轉
        /// </summary>
        /// <param name="page">當前頁面指針一般為this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳轉的目標URL</param>
        public static void ShowAndRedirect(SystemWebUIPage page string msg string url string frame)
        {
            StringBuilder Builder = new StringBuilder();
            BuilderAppend("<script language=javascript defer>");
            BuilderAppendFormat("alert({});" msg);
            BuilderAppendFormat("top" + frame + "location" url);
            BuilderAppend("</script>");
            pageClientScriptRegisterStartupScript(pageGetType() "message" BuilderToString());
        }
        /// <summary>
        /// 輸出自定義腳本信息
        /// </summary>
        /// <param name="page">當前頁面指針一般為this</param>
        /// <param name="script">輸出腳本</param>
        public static void ResponseScript(SystemWebUIPage page string script)
        {
            pageClientScriptRegisterStartupScript(pageGetType() "message" "<script language=javascript defer>" + script + "</script>");
        }
        /// <summary>
        /// 顯示消息提示對話框並進行頁面跳轉
        /// <param name="page">當前頁面指針一般為this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳轉的目標URL</param>
        public static void ShowAndRedirect(SystemWebUIPage page string msg string url)
        {
            StringBuilder Builder = new StringBuilder();
            BuilderAppend("<script language=javascript defer>");
            BuilderAppendFormat("alert({});" msg);
            BuilderAppendFormat("toplocation" url);
            BuilderAppend("</script>");
            pageClientScriptRegisterStartupScript(pageGetType() "message" BuilderToString());
       }
}
}


From:http://tw.wingwit.com/Article/program/net/201311/14134.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.