这篇文章介绍了ASP
NET打开新页面而不关闭原来的页面 实例代码
有需要的朋友可以参考一下
希望对你有所帮助
复制代码 代码如下:
Respose
Write("<script language=
javascript
>window
open(
"+ url +"
);</script>"); (打开简洁窗口)
Respose
Write("<script language=
javascript
>window
open(
" + url + "
resizable=
scrollbars=
status=
menubar=no
toolbar=no
location=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(System
Web
UI
Page page
string msg)
{
page
ClientScript
RegisterClientScriptBlock(page
GetType()
"a"
"alert(
" + msg
ToString() + "
);"
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());
}
}
}