






















前提条件:B页面是由A页面打开的。
方法:
在A页面的前台代码中加入以下代码:
<script language="javascript">function DownDvasp(htmlurl){var
newwin=window.open(htmlurl,'','toolbar=no,location=no,directories=no,status=no,menub
ar=no,scrollbars=no,resizable=no');return false;}</script>
此代码如果在继承母版页的asp.net页面中就需要加在<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">行下。
如果在一般的asp.net页面中就需加在<HEAD>段中。
然后在需链接打开的位置加入:
<a href="B.aspx?id=<%# Eval("id")%>" onclick="return DownDvasp(this.href);">回复此留
言</a>
这样单击此链接就可打开一个窗口了。
在B页面的前台代码中加入以下代码:
<input type='button' value='关闭窗口'
onclick='javascript:window.opener.location.href="A.aspx";window.close();''>
这样就实现了关闭B窗口的同时重新刷新A窗口的目地。
若只是关闭窗口而不需重新刷新A窗口,只需改成onclick='window.close()'就行了。
下面是我所做的一个回复留言的完整代码:
liuyanmanager.aspx
<%@ Page Language="C#" MasterPageFile="~/admin/MasterPageadmin.master"
AutoEventWireup
="true" CodeFile="liuyanmanager.aspx.cs"Inherits
="admin_liuyanmanager" Title="Untitled Page" %>Runat
="Server">newwin
=window.open(htmlurl,'','toolbar=no,location=no,directories=no,status=no,menubar
=no,scrollbars=no,resizable=no');return false;}</script>DataKeyNames
="id"%
>' Visible="False"></asp:Label>DataSourceID
="SqlDataSourceuser">Text
='<%# Bind("UserName") %>'></asp:Label><br />ConnectionString
="<%$ ConnectionStrings:ASPNETDBConnectionString %>"WHERE (UserId = @userid)"
>PropertyName
="Text" />%
>'></asp:Label>DownDvasp(this.href);">回复此留言
</a>ConnectionStrings:articleConnectionString %>"
(hufu = N'未回复')"
>hufu.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="hufu.aspx.cs"
Inherits
="admin_hufu" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
><html xmlns="http://www.w3.org/1999/xhtml" >style
="width: 500px">DataSourceID
="SqlDataSource1" Width="500px">style
="width: 480px">align
="center" valign="top">Text
='<%# Bind("userid") %>' Visible="False"></asp:Label><asp:FormViewDataSourceID
="SqlDataSourceuser">runat
="server" Text='<%# Bind("UserName") %>'></asp:Label>的留言:<br />runat
="server" Height="80px" ReadOnly="True" Text='<%# Bind("liuyan") %>'Width="480px">
</asp:TextBox></td>runat
="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"FROM vw_aspnet_Users WHERE (UserId = @UserId)"
>TextMode
="MultiLine" Width="480px"></asp:TextBox></td>OnClick
="Button1_Click" />ConnectionStrings:articleConnectionString %>"
WHERE ([id] = @id)"
>Type
="Int32" />
'"+Request.QueryString["id"]+"'";
using (SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrings["articleConnectionString"].Conn
ectionString))
{
using (SqlCommand command = new SqlCommand(sql, connection))
{
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
posted on 2006-06-26 04:11 E海星 阅读(609) 评论(1) 编辑 收藏 引用 网摘 所属分类: ASP.NET 2.0学习笔记
Feedback
# re: 如何在asp.net中关闭B页面时,自动刷新A页面? 2006-09-11 12:02 what
假设分别是1.asp和2.asp
------1.asp
..
..
..
<form action=2.asp method=post>
.
</form>
----------2.asp
<meta http-equiv="refresh" content="2; url=1.asp"> '不要忘记在head区加这句
<%
if request("txtn1")<>"" then
for i=1 to cint(request("txtn1"))
s="delete from cyprice where id = " & trim(request("txtep1" & cstr(i)))
rs.open s,conn,3,2
next
response.redirect "cyjc.asp"
end if
%>
在由2.asp转回1.asp的时候刷新了1.asp。
=====================================================================================
使用window.location.reload;刷新时,如果提交数据的动作,则会出现这么个讨厌的对话框!

解决此问题,应该这样写:
window.location.href=window.location.href;
window.location.reload;
同理,如果是刷新父窗口,应该这样写:
window.opener.location.href=window.opener.location.href;
window.location.reload;
这种写法就不出现那讨厌的对话框啦!
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1482799
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。