如何从C#codebehind关闭一个窗口? [英] How to close a Window from C# codebehind?

查看:60
本文介绍了如何从C#codebehind关闭一个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,


我只想打开一个弹出窗口打印报告,调用打印

函数并在用户拥有后关闭窗口打印了

报告。


我有2个函数....在c#


Onload事件寄存器从c#关闭窗口的脚本。

FillReport函数填充gridview


我有一个JavaScript函数AssignContent();简单地调用

window.print()和window.close()

此代码在Firefox中正常运行但窗口未关闭

Internet Explorer 6


我也在给代码... plz建议我一些解决方案..我只是

无法关闭窗口在ie6。


这是代码....


C#代码

----- ----------------------------------------------

protected void Page_Load(object sender,EventArgs e)

{

if(!IsPostBack)

{


fillreport();

if(!ClientScript.IsClientScriptBlockRegistered(" k1"))

{

ClientScript .RegisterClientScriptBlock(this.GetTyp e(),

" k1","< script language =''javascript''> AssignContent();< /

script>");

}

}

}


private void fillreport ()

{

//填充网格w $ / $
}


// JavaScript

----------------- --------------------

函数AssignContent()

{

window .print();

window.close();

}



问候,

Mahernoz

解决方案

Mahernoz,你有没有解决过这个问题?我有同样的问题,并且

我看到没有人回复你。


Jeremy


" Mahernoz" < ma ****** @ gmail.com在留言中写道

news:11 ********************* @ w3g2000hsg。 googlegrou ps.com ...


嗨朋友们,


我只是想通过弹出一个弹出窗口来打印报告,在用户打印

报告后调用打印

功能并关闭窗口。


我有2个功能.. .. in c#


Onload事件注册一个脚本来关闭c#窗口。

FillReport函数填充gridview


我有一个JavaScript函数AssignContent();简单地调用

window.print()和window.close()

此代码在Firefox中正常运行但窗口未关闭

Internet Explorer 6


我也在给代码... plz建议我一些解决方案..我只是

无法关闭窗口在ie6。


这是代码....


C#代码

----- ----------------------------------------------

protected void Page_Load(object sender,EventArgs e)

{

if(!IsPostBack)

{


fillreport();

if(!ClientScript.IsClientScriptBlockRegistered(" k1"))

{

ClientScript .RegisterClientScriptBlock(this.GetTyp e(),

" k1","< script language =''javascript''> AssignContent();< /

script>");

}

}

}


private void fillreport()

{

//填写网格视图

}


// JavaScript

-------------------------------- -----

函数AssignContent()

{

window.print();

窗口。关闭();

}


问候,

Mahernoz


" Mahernoz" < ma ****** @ gmail.com在留言中写道

news:11 ********************* @ w3g2000hsg。 googlegrou ps.com ...


我根本无法在IE6中关闭窗口。



尝试时会发生什么...?


ClientScript.RegisterClientScriptBlock(this.GetTyp e( ),k1,< script

language =''javascript''> AssignContent();< / script>");



如果你使用布尔重载,那将自动添加< scripttags

,这样你就可以避免使用不推荐使用的语法...


ClientScript.RegisterClientScriptBlock(GetType()," k1"," AssignContent();",

true);


函数AssignContent()

{

window.print();

window.close() ;

}



尝试添加window.opener = null;上述两个陈述之间...

-

Mark Rae

ASP.NET MVP
http://www.markrae.net


< blockquote> Mark,谢谢你跳进来。


我承认我不知道Mahernoz是如何试图执行他的

javascript的。在我的情况下,我只是做了以下(在使用你的

关于开启者的建议之后)。仍然无法正常工作。可能是非常好的东西

基本我没有得到。


protected void OnLoggedIn(对象发送者,EventArgs e)

{

Response.Write("< script language =

javascript> window.opener = null; window.close();< / script>");

}


Jeremy


" Mark Rae [MVP]" < ma ** @ markNOSPAMrae.netwrote in message

news:eC ************** @ TK2MSFTNGP05.phx.gbl ...
< blockquote class =post_quotes>
" Mahernoz" < ma ****** @ gmail.com在留言中写道

news:11 ********************* @ w3g2000hsg。 googlegrou ps.com ...


>我根本无法在IE6中关闭窗口。



尝试时会发生什么...?


> ClientScript.RegisterClientScriptBlock(this.GetTy pe(),k1,< script
language =''javascript''> AssignContent();< / script>");



如果你使用布尔重载,那将自动添加< scripttags

,这样你就可以避免使用不推荐使用的语法...


ClientScript.RegisterClientScriptBlock(GetType()," k1",

" AssignContent();",true);


> function AssignContent()
{
window.print();
window.close();
}



尝试添加window.opener = null;上述两个陈述之间...


-

Mark Rae

ASP.NET MVP
http://www.markrae.net


Hi Friends,

I simply want to print a report by opening a popup, calling the print
function and closing the window after the user has printed the
report.

I have 2 functions.... in c#

The Onload event registers a script to close the window from c#. The
FillReport functions fills a gridview

I have a JavaScript Function AssignContent(); which simply calls
window.print() and window.close()

This code runs fine in Firefox but the window is not closing in
Internet Explorer 6

I am also giving the code ... plz suggest me some solution.. i simply
cannot close the window in ie6.

Here is the code....

C# Code
---------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

fillreport();
if (!ClientScript.IsClientScriptBlockRegistered("k1") )
{
ClientScript.RegisterClientScriptBlock(this.GetTyp e(),
"k1", "<script language=''javascript''>AssignContent();</
script>");
}
}
}

private void fillreport()
{
//fills a gridview
}

//JavaScript
-------------------------------------
function AssignContent()
{
window.print();
window.close();
}


Regards,
Mahernoz

解决方案

Mahernoz, did you ever resolve this question? I have the same problem, and
I see that no one has replied to you.

Jeremy

"Mahernoz" <ma******@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...

Hi Friends,

I simply want to print a report by opening a popup, calling the print
function and closing the window after the user has printed the
report.

I have 2 functions.... in c#

The Onload event registers a script to close the window from c#. The
FillReport functions fills a gridview

I have a JavaScript Function AssignContent(); which simply calls
window.print() and window.close()

This code runs fine in Firefox but the window is not closing in
Internet Explorer 6

I am also giving the code ... plz suggest me some solution.. i simply
cannot close the window in ie6.

Here is the code....

C# Code
---------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

fillreport();
if (!ClientScript.IsClientScriptBlockRegistered("k1") )
{
ClientScript.RegisterClientScriptBlock(this.GetTyp e(),
"k1", "<script language=''javascript''>AssignContent();</
script>");
}
}
}

private void fillreport()
{
//fills a gridview
}

//JavaScript
-------------------------------------
function AssignContent()
{
window.print();
window.close();
}


Regards,
Mahernoz


"Mahernoz" <ma******@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...

I simply cannot close the window in IE6.

What happens when you try...?

ClientScript.RegisterClientScriptBlock(this.GetTyp e(), "k1", "<script
language=''javascript''>AssignContent();</script>");

If you use the boolean overload, that will add the <scripttags
automatically so you avoid using the deprecated syntax...

ClientScript.RegisterClientScriptBlock(GetType(), "k1", "AssignContent();",
true);

function AssignContent()
{
window.print();
window.close();
}

Try adding window.opener=null; between the two statements above...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Mark, thanks for jumping in here.

I confess that I don''t understand how Mahernoz was attempting to execute his
javascript. In my case, I simply did the following (after using your
suggestion about opener). Still does not work. Probably something very
basic I don''t get.

protected void OnLoggedIn(object sender, EventArgs e)
{
Response.Write ("<script language =
javascript>window.opener=null; window.close();</script>");
}

Jeremy

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:eC**************@TK2MSFTNGP05.phx.gbl...

"Mahernoz" <ma******@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...

>I simply cannot close the window in IE6.


What happens when you try...?

>ClientScript.RegisterClientScriptBlock(this.GetTy pe(), "k1", "<script
language=''javascript''>AssignContent();</script>");


If you use the boolean overload, that will add the <scripttags
automatically so you avoid using the deprecated syntax...

ClientScript.RegisterClientScriptBlock(GetType(), "k1",
"AssignContent();", true);

>function AssignContent()
{
window.print();
window.close();
}


Try adding window.opener=null; between the two statements above...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


这篇关于如何从C#codebehind关闭一个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆