惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cisco Talos Blog
Cisco Talos Blog
T
Threat Research - Cisco Blogs
P
Privacy International News Feed
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
Scott Helme
Scott Helme
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
O
OpenAI News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
PCI Perspectives
PCI Perspectives
GbyAI
GbyAI
宝玉的分享
宝玉的分享
Y
Y Combinator Blog
T
Troy Hunt's Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
腾讯CDC
C
Check Point Blog
Spread Privacy
Spread Privacy
L
LINUX DO - 最新话题
Recent Announcements
Recent Announcements
大猫的无限游戏
大猫的无限游戏
P
Palo Alto Networks Blog
Hacker News: Ask HN
Hacker News: Ask HN
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
T
Tor Project blog
Martin Fowler
Martin Fowler
博客园 - 叶小钗
罗磊的独立博客
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Heimdal Security Blog
V
Vulnerabilities – Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
Latest news
Latest news
WordPress大学
WordPress大学
G
Google Developers Blog
N
Netflix TechBlog - Medium
S
Security Affairs
S
Secure Thoughts
Know Your Adversary
Know Your Adversary

博客园 - 星空竹月

Div中文字竖直居中的问题 ASP入门基础教程-VBScript概述及基本元素 第一次安装sql2000挂起无法安装的问题 asp.net(c#)成条形码[转] 关于文章列表如何直接显示文章类别名的问题 Page_PreInit在网页传值的应用 利用.net的强大功能发送email - 星空竹月 - 博客园 在页面和Datalist控件中判断是否为今天 - 星空竹月 - 博客园 ASP.net(c#)做返回上一页效果(后退)--代码 前进和后退按钮特效代码 - 星空竹月 - 博客园 文件上传实例(文件上传,自动重命名,自动添加文件夹) ASP.NET中文显示乱码之解决方法 限制显示字数 asp.net中,限制显示字数的问题? 将截断字符串或二进制数据。 IE6下透明PNG图片的显示 IE不支持PNG图片透明效果,怎么办 配置AjaxControlToolkit 怎样换网页中的鼠标图案??换成其他图片
如何在asp.net中关闭B页面时,自动刷新A页面? - 星空竹月 - 博客园
星空竹月 · 2007-09-10 · via 博客园 - 星空竹月

前提条件: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" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" 

Runat

="Server">
<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:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 

DataKeyNames

="id"
        DataSourceID
="SqlDataSourcehufu" Width="100%">
        
<Columns>
            
<asp:TemplateField HeaderText="会员名" SortExpression="userid">
                 
<ItemTemplate>
                    
<asp:Label ID="Label1" runat="server" Text='<%# Bind("userid") 

%

>' Visible="False"></asp:Label>
                    
<asp:FormView ID="FormView1" runat="server" 

DataSourceID

="SqlDataSourceuser">
                        
<ItemTemplate>
                            
&nbsp;<asp:Label ID="UserNameLabel" runat="server" 

Text

='<%# Bind("UserName") %>'></asp:Label><br />
                        
</ItemTemplate>
                    
</asp:FormView>
                    
<asp:SqlDataSource ID="SqlDataSourceuser" runat="server" 

ConnectionString

="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
                        SelectCommand
="SELECT UserId, UserName FROM vw_aspnet_Users 

WHERE (UserId = @userid)"

>
                        
<SelectParameters>
                            
<asp:ControlParameter ControlID="Label1" Name="userid" 

PropertyName

="Text" />
                        
</SelectParameters>
                    
</asp:SqlDataSource>
                
</ItemTemplate>
            
</asp:TemplateField>
            
<asp:TemplateField HeaderText="留言" SortExpression="liuyan">
                
<ItemTemplate>
                    
<asp:Label ID="Label2" runat="server" Text='<%# Bind("liuyan") 

%

>'></asp:Label>
                
</ItemTemplate>
                
<ItemStyle Width="520px" />
            
</asp:TemplateField>
            
<asp:TemplateField HeaderText="留言时间" SortExpression="liuyantime">
                
<ItemTemplate>
                    
<asp:Label ID="Label4" runat="server" Text='<%# Bind("liuyantime") %>'></asp:Label>
                
</ItemTemplate>
            
</asp:TemplateField>
            
<asp:TemplateField HeaderText="回复">
                
<ItemTemplate>
                    
&nbsp;<href="hufu.aspx?id=<%# Eval("id")%>" onclick="return 

DownDvasp(this.href);">回复此留言

</a> 
                
</ItemTemplate>
            
</asp:TemplateField>
        
</Columns>
    
</asp:GridView>
    
<asp:SqlDataSource ID="SqlDataSourcehufu" runat="server" ConnectionString="<%$ 

ConnectionStrings:articleConnectionString %>"


        SelectCommand
="SELECT id, userid, liuyan, hufu, liuyantime FROM liuyan WHERE 

(hufu = N'未回复')"

>
    
</asp:SqlDataSource>
</asp:Content>

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" >
<head runat="server">
    
<title>回复留言</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<table align="center" border="0" cellpadding="0" cellspacing="0" 

style

="width: 500px">
            
<tr>
                
<td style="width: 500px">
                
</td>
            
</tr>
            
<tr>
                
<td style="width: 500px">
                    
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id" 

DataSourceID

="SqlDataSource1" Width="500px">
                        
<ItemTemplate>
                            
<table border="0" cellpadding="0" cellspacing="0" 

style

="width: 480px">
                                
<tr>
                                    
<td width="480" style="text-align: center" 

align

="center" valign="top">
                                        
<asp:Label ID="useridLabel" runat="server" 

Text

='<%# Bind("userid") %>' Visible="False"></asp:Label><asp:FormView
                                            
ID="FormView2" runat="server" 

DataSourceID

="SqlDataSourceuser">
                                            
<ItemTemplate>
                                                来自
                                                
&nbsp;<asp:Label ID="UserNameLabel" 

runat

="server" Text='<%# Bind("UserName") %>'></asp:Label>的留言:<br />
                                            
</ItemTemplate>
                                        
</asp:FormView>
                                        
</td>
                                
</tr>
                                
<tr>
                                    
<td width="480" align="center">
                                        
&nbsp;<asp:TextBox ID="TextBox1" 

runat

="server" Height="80px" ReadOnly="True" Text='<%# Bind("liuyan") %>'
                                            TextMode="MultiLine" 

Width="480px">

</asp:TextBox></td>
                                
</tr>
                            
</table>
                                        
<asp:SqlDataSource ID="SqlDataSourceuser" 

runat

="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
                                            SelectCommand
="SELECT UserId, UserName 

FROM vw_aspnet_Users WHERE (UserId = @UserId)"

>
                                            
<SelectParameters>
                                                
<asp:ControlParameter ControlID="useridLabel" Name="UserId" PropertyName="Text" />
                                            
</SelectParameters>
                                        
</asp:SqlDataSource>
                            
                        
</ItemTemplate>
                    
</asp:FormView>
                
</td>
            
</tr>
            
<tr>
                
<td style="width: 500px">
                    回复:
</td>
            
</tr>
            
<tr>
                
<td align="left" style="width: 500px">
                    
<asp:TextBox ID="txthufu" runat="server" Height="80px" 

TextMode

="MultiLine" Width="480px"></asp:TextBox></td>
            
</tr>
            
<tr>
                
<td align="center" style="width: 500px">
                    
<asp:Button ID="Button1" runat="server" Text="回复" 

OnClick

="Button1_Click" />
                    
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<input type='button' value='关闭窗口' onclick='javascript:window.opener.location.href="liuyanmanager.aspx";window.close();''></td>
            
</tr>
        
</table>
    
    
</div>
        
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ 

ConnectionStrings:articleConnectionString %>"


            SelectCommand
="SELECT [id], [userid], [liuyan], [hufu] FROM [liuyan] 

WHERE ([id] = @id)"

>
            
<SelectParameters>
                
<asp:QueryStringParameter Name="id" QueryStringField="id" 

Type

="Int32" />
            
</SelectParameters>
        
</asp:SqlDataSource>
    
</form>
</body>
</html>
hufu.aspx的部分后台代码:
protected void Button1_Click(object sender, EventArgs e)
    {
        string hufustring = this.txthufu.Text.Trim();
        if (hufustring != "" && hufustring != string.Empty)
        {
            hufustring = hufustring.Replace("'", "“");
            string sql = "UPDATE liuyan SET hufu ='"+hufustring+"' WHERE id = 

'"+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