如何在asp.net中关闭B页面时,自动刷新A页面?

前提条件: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")%>" οnclick="return DownDvasp(this.href);">回复此留

言</a>
这样单击此链接就可打开一个窗口了。
在B页面的前台代码中加入以下代码:
<input type='button' value='关闭窗口'

οnclick='javascript:window.opener.location.href="A.aspx";window.close();''>
这样就实现了关闭B窗口的同时重新刷新A窗口的目地。

若只是关闭窗口而不需重新刷新A窗口,只需改成οnclick='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;<a href="hufu.aspx?id=<%# Eval("id")%>" οnclick="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='关闭窗口'

οnclick='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-11-02 13:16  suny2006 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/suny2006/archive/2006/11/02/547769.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值