1/1页1 跳转到查看:2043
发新话题 回复该主题

请教,如何让页面自己关闭

请教,如何让页面自己关闭

我的意思时说:在页面中定义一个Button,当点击Button时 ,调用OnClick事件关闭当前页面页!请教各位前辈,如何写代码?

TOP

 

回复:请教,如何让页面自己关闭

Response.Write("<script>window.close();</script>");// 会弹出询问是否关闭
Response.Write("<script>window.opener=null;window.close();</script>");// 不会弹出询问
本帖被评分 1 次
路漫漫其修远兮 吾将上下而求索

TOP

 

回复: 请教,如何让页面自己关闭



引用:
原帖由 suresy 于 2008-6-19 15:06:00 发表
Response.Write("<script>window.close();</script>");// 会弹出询问是否关闭
Response.Write("<script>window.opener=null;window.close();</script>");// 不会弹出询......


回复的经典。加金币
http://www.Aspx1.Com
请帮忙宣传Aspx1 , Aspx1是ASP.NET学习者的家园 , 适宜长期居住.

TOP

 

回复:请教,如何让页面自己关闭

谢谢!

TOP

 

回复:请教,如何让页面自己关闭

以下是我的测试代码:

<%@ Language="C#" %>

<script language="C#" runat="server">

void Btn_Close(object sender ,EventArgs e)

{

    Response.Write("<script>window.opener=null;window.close();</script>");// 不会弹出询......

}


void Btn_Click(object sender ,EventArgs e)
{

    Response.Write("<script>window.close();</script>");// 会弹出询问是否关闭

}

</script>

<form runat="server">
<p><asp:Button id="Button1" Text="不弹出对话框Close" width="200px" OnClick="Btn_Close" runat="server" />

<p><asp:Button id="Button2" Text="弹出对话框的Close" width="200px" OnClick="Btn_Click" runat="server" />
</form>

出现了如下编译信息:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1010: Newline in constant

Source Error:

Line 7:  {
Line 8: 
Line 9:      Response.Write("<script>window.opener=null;window.close();</script>");// 不会弹出询......
Line 10:
Line 11: }

Source File: c:\Inetpub\wwwroot\MyWebSite\Close_IE.aspx    Line: 9
Show Detailed Compiler Output:


C:\WINDOWS\system32> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\77143044\e1bbbc9c\App_Web_6genyji7.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699  "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\77143044\e1bbbc9c\App_Web_6genyji7.0.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\77143044\e1bbbc9c\App_Web_6genyji7.1.cs"


Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

c:\Inetpub\wwwroot\MyWebSite\Close_IE.aspx(9,17): error CS1010: Newline in constant
c:\Inetpub\wwwroot\MyWebSite\Close_IE.aspx(9,60): error CS1513: } expected

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42


请问是什么原因?谢谢!

TOP

 

回复:请教,如何让页面自己关闭

好像是因为Response.Write里面的<script>和页面的<script>标签有冲突,最好把后台代码放在单独的文件中不要和页面代码混在一起。
路漫漫其修远兮 吾将上下而求索

TOP

 

回复:请教,如何让页面自己关闭

可能楼主的客户段事件和服务器段事件的理解方面还需要加强,其实这种操作是纯客户段的,最好不要postback到服务器段了。
改成这样:

<form runat="server">
<p><asp:Button id="Button1" Text="不弹出对话框Close" width="200px" OnClientClick="window.opener=null;window.close();" runat="server" />

<p><asp:Button id="Button2" Text="弹出对话框的Close" width="200px" OnClientClick="window.close();" runat="server" />
</form>


http://www.Aspx1.Com
请帮忙宣传Aspx1 , Aspx1是ASP.NET学习者的家园 , 适宜长期居住.

TOP

 

回复:请教,如何让页面自己关闭

看楼主的意思是要关闭页面, 楼上校长说的对这种操作纯客户端的 那么就不要postback到服务器段了,你的button控件可以用html控件
可改成这样:
<input id="Button1" type="button" value="button" onclick="window.opener=null;window.close();" />
        <input id="Button2" type="button" value="button" onclick="window.close();" />

TOP

 

回复: 请教,如何让页面自己关闭



引用:
原帖由 zorosuteng 于 2008-6-24 8:27:00 发表
看楼主的意思是要关闭页面, 楼上校长说的对这种操作纯客户端的 那么就不要postback到服务器段了,你的button控件可以用html控件
可改成这样:
<input id="Button1" type="button" value=&......

的确啊,都关闭页面了,也就无法postback到服务器段了,索性用input更轻便些。

TOP

 

回复:请教,如何让页面自己关闭

onclick="window.close();"

TOP

 
1/1页1 跳转到
发表新主题 回复该主题