Masterpage - window.showModalDialog - window.close

  • Thread starter Thread starter kurt sune
  • Start date Start date
K

kurt sune

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.GetType(), "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.close();}</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.GetType(), "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
 
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
 
Back
Top