您好,登錄后才能下訂單哦!
本篇內容主要講解“如何實現ASP.NET打開新頁面而不關閉原來的頁面”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何實現ASP.NET打開新頁面而不關閉原來的頁面”吧!
復制代碼 代碼如下:
Respose.Write("<script language='javascript'>window.open('"+ url +"');</script>"); (打開簡潔窗口):
Respose.Write("<script language='javascript'>window.open('" + url + "','','resizable=1,scrollbars=0,status=1,menubar=no,toolbar=no,location=no, menu=no');</script>");
1. Response.Redirect("XXX.aspx",true)——直接轉向新的頁面,原窗口被代替;
2. Response.Write("<script>window.open('XXX.aspx','_blank')</script>")——原窗口保留,另外新增一個新頁面;
3. Response.Write("<script>window.location='XXX.aspx'</script>")——打開新的頁面,原窗口被代替;
4. Server.Transfer("XXX.aspx")——打開新的頁面;
5. Response.Write("<script>window.showModelessDialog('XXX.aspx')</script>")——原窗口保留,以對話框形式打開新窗口;
6. Response.Write("<script>window.showModelDialog('XXX.aspx')</script>")——對話框形式打開新窗口,原窗口被代替;
也可以自己寫方法:
復制代碼 代碼如下:
public static void ShowMessage(System.Web.UI.Page page, string msg)
{
page.ClientScript.RegisterClientScriptBlock(page.GetType(), "a", "alert('" + msg.ToString() + "');", true);
}
調用的時候:
ShowMessage(this,"要顯示的消息");
下面是整個類的代碼你可以挑著用
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace WorkLogic
{
/// <summary>
/// 顯示消息提示對話框。
/// </summary>
public class MessageBox
{
private MessageBox()
{
}
/// <summary>
/// 顯示消息提示對話框
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="msg">提示信息</param>
public static void ShowMessage(System.Web.UI.Page page, string msg)
{
//page.RegisterStartupScript("message", "alert('" + msg.ToString() + "');");
page.ClientScript.RegisterClientScriptBlock(page.GetType(), "a", "alert('" + msg.ToString() + "');", true);
}
public static void ShowMessage(System.Web.UI.UserControl control, string msg)
{
control.Page.ClientScript.RegisterClientScriptBlock(control.Page.GetType(), "b", "alert('" + msg.ToString() + "');", true);
}
/// <summary>
/// 控件點擊 消息確認提示框
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="msg">提示信息</param>
public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
{
//Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
}
/// <summary>
/// 顯示消息提示對話框,并進行頁面跳轉
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="msg">提示信息</param>
/// <param name="url">跳轉的目標URL</param>
public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url, string frame)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');", msg);
Builder.AppendFormat("top." + frame + ".location.href='{0}'", url);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 輸出自定義腳本信息
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="script">輸出腳本</param>
public static void ResponseScript(System.Web.UI.Page page, string script)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "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(System.Web.UI.Page page, string msg, string url)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');", msg);
Builder.AppendFormat("top.location.href='{0}'", url);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
}
}
到此,相信大家對“如何實現ASP.NET打開新頁面而不關閉原來的頁面”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。