473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Masterpage - window.showModalDialog - window.close

Hello, I have a weird problem, I hope someone can explain this for me.

I have a webpage using masterpage.
In it I create a popup window using this code:
Dim js As String = "<script language=javascript>"

js &= "var newWin = window.showModalDialog('InkommetVi.aspx"

js &= "',null,"

js &= "'center:yes; resizable:yes;help:no;dialogHeight:600px;
dialogWidth:750px;edge: Raised;status: No;');"

js &= "</script"

Me.Page.ClientScript.RegisterStartupScript(Me.GetT ype(), "InkommetV", js)

The popup window gets displayed all right.

The popup window has a close button declared thus:

<asp:Button ID="btnClose" runat="server" Text="Close" />

And in it's clickevent I try to close the window: Response.Write("<script
language='javascript'{window.close();}</script>")

It doesn't work.

I have tried with these: (they work on pages not using masterpage)

ClientScript.RegisterStartupScript(Me.GetType(), "cwin", "window.close();")

Response.Write("<script language='javascript'{window.opener = 'x';
window.close();}</script>")

Response.Write("<script language='javascript'{window.opener = '';
window.close();}</script>")

Response.Write("<script language='javascript'{this.focus();self.opener =
this;self.close();}</script>")

Response.Write("<script language='javascript'{top.window.opener =
top;top.window.open('','_parent','');top.window.cl ose();}</script>")

Response.Write("<script language='javascript'>
{window.open('','_self');window.close();}</script>")

Response.Write("<script language='javascript'{window.opener = self;
window.close();}</script>")

Dim sScript As String = "<SCRIPT language='javascript'"

sScript &= "window.close();"

sScript &= "</SCRIPT>"

Page.ClientScript.RegisterClientScriptBlock(Me.Get Type(), "InkommetVi",
sScript)

Neither of them works.

What does work however is this code on the page:

<script type="text/javascript">

window.onunload=st;

function st()

{

window.close();

}

</script>

<input id="Button1" type="button" value="Close" onclick="st();" />

Can anybody explain this to me?

/k


Aug 18 '08 #1
2 6733
Instead of using Response.Write statements, use a literal. A literal is
designed to take HTML and output it raw. This way you can get the placement
on the page correct as who knows where it will get displayed using a
Response.Write statement since that's not very conducive to event-driven
environments.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

"kurt sune" <ap*@apa.comwrote in message
news:Ol**************@TK2MSFTNGP02.phx.gbl...
Hello, I have a weird problem, I hope someone can explain this for me.

I have a webpage using masterpage.
In it I create a popup window using this code:
Dim js As String = "<script language=javascript>"

js &= "var newWin = window.showModalDialog('InkommetVi.aspx"

js &= "',null,"

js &= "'center:yes; resizable:yes;help:no;dialogHeight:600px;
dialogWidth:750px;edge: Raised;status: No;');"

js &= "</script"

Me.Page.ClientScript.RegisterStartupScript(Me.GetT ype(), "InkommetV", js)

The popup window gets displayed all right.

The popup window has a close button declared thus:

<asp:Button ID="btnClose" runat="server" Text="Close" />

And in it's clickevent I try to close the window: Response.Write("<script
language='javascript'{window.close();}</script>")

It doesn't work.

I have tried with these: (they work on pages not using masterpage)

ClientScript.RegisterStartupScript(Me.GetType(), "cwin",
"window.close();")

Response.Write("<script language='javascript'{window.opener = 'x';
window.close();}</script>")

Response.Write("<script language='javascript'{window.opener = '';
window.close();}</script>")

Response.Write("<script language='javascript'{this.focus();self.opener =
this;self.close();}</script>")

Response.Write("<script language='javascript'{top.window.opener =
top;top.window.open('','_parent','');top.window.cl ose();}</script>")

Response.Write("<script language='javascript'>
{window.open('','_self');window.close();}</script>")

Response.Write("<script language='javascript'{window.opener = self;
window.close();}</script>")

Dim sScript As String = "<SCRIPT language='javascript'"

sScript &= "window.close();"

sScript &= "</SCRIPT>"

Page.ClientScript.RegisterClientScriptBlock(Me.Get Type(), "InkommetVi",
sScript)

Neither of them works.

What does work however is this code on the page:

<script type="text/javascript">

window.onunload=st;

function st()

{

window.close();

}

</script>

<input id="Button1" type="button" value="Close" onclick="st();" />

Can anybody explain this to me?

/k

Aug 18 '08 #2
"kurt sune" <ap*@apa.comwrote in message
news:Ol**************@TK2MSFTNGP02.phx.gbl...
Hello, I have a weird problem, I hope someone can explain this for me.
In addition to Mark's reply...
Dim js As String = "<script language=javascript>"
The language tag has been deprecated for ages:
http://www.w3.org/TR/REC-html40/inte....html#h-18.2.1

Use <script type="text/javascript"instead...

js &= "var newWin = window.showModalDialog('InkommetVi.aspx"
showModalDialog is *completely* non-standard, and is supported only by
Microsoft IE and Apple Safari. Consider using this instead:
http://www.asp.net/ajax/ajaxcontrolt...odalpopup.aspx

Dim sScript As String = "<SCRIPT language='javascript'"
sScript &= "</SCRIPT>"
Assuming you're writing your markup to XHTML standard compliance, the above
will fail validation because you're using upper-case tags...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 18 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: KS | last post by:
Is it possible to write a javascript that makes a popup window when someone click on buttons/href on my page and close itself when the new page is about to get loaded? I want to prevent the user...
3
by: jayuya | last post by:
I have a simple page that I will like to display while i am processing the user request in the server. The page only has a label saying "Please Wait..." My objective is to show this window while...
6
by: Scott Lee | last post by:
I am displaying an ASP.Net generated form in a popup opened with window.showModalDialog. The form contains DropDownList controls. The first ddl is populated via databinding to a datatable, has...
3
by: Paul K | last post by:
I'm not quite sure if the problem I'm having is a restriction of showModalDialog or if there is a way around it. The web app I am working requires the user to select a record from a list. I pop...
1
by: John | last post by:
Hi, I'm having a problem opening / downloading csv files when called from a page opened with window.showModalDialog( ). To isolate this problem, I've written 3 files (see below). 1. main.htm...
2
by: John | last post by:
Hi, I posted this earlier in microsoft.public.dotnet.framework.aspnet, but didn't get a response, so I thought I'd try here. Basically, I'm having a problem opening / downloading csv files...
1
by: Curious Trigger | last post by:
Hi there, programming with Visual Studio 2005 and ASP.NET 2.0 I want to open a modal dialog from Default.aspx. I searched the net and many newsgroups but I couldn't find any solution. First I...
9
by: Stan B | last post by:
I create a popup window by calling window.showModalDialog Popup window has Ok button with this code attached: === string Script = "<script language=JavaScript>" + "{" + "window.close();" +...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.