asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET打开新页面而不关闭原来的页面 实例代码


发布日期:2019年01月07日
 
ASP.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());
}
}
}

上一篇:asp.net跳转页面的三种方法

下一篇:asp.net 初始化文本框的小例子