showModalDialog window does not close

S

Stan B

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();" +
"}" +
"</script>";

if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
ClientScript.RegisterClientScriptBlock (Page.GetType(),
"CloseScript", Script);

===

When Ok button is clilcked, the window is flickering but does not close.

1. If window.showModalDialog is replaced with window.open, everything works
fine.

2. Similar code worked fine on 1.1 framework

3. There is a workaround to set window.opener to some value. I tried that -
didn't work

Thanks,

-Stan
 
E

Eliyahu Goldin

Stan,

Would not it be easier to put the script straight to the <head> section of
the aspx page, setup the button's onclick event and stop worrying about the
script registration calls?
 
S

Stan B

Eliyahu, it would. But how can I solve my problem of window not being
closed?

Eliyahu Goldin said:
Stan,

Would not it be easier to put the script straight to the <head> section of
the aspx page, setup the button's onclick event and stop worrying about
the script registration calls?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
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();" +
"}" +
"</script>";

if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
ClientScript.RegisterClientScriptBlock (Page.GetType(),
"CloseScript", Script);

===

When Ok button is clilcked, the window is flickering but does not close.

1. If window.showModalDialog is replaced with window.open, everything
works fine.

2. Similar code worked fine on 1.1 framework

3. There is a workaround to set window.opener to some value. I tried
that - didn't work

Thanks,

-Stan
 
B

bruce barker \(sqlwork.com\)

when a modal dialog box postbacks, it does not postbck to the same window,
so the client script you generate is not running in the popup window. to
postback to the same window, have a frameset page host the dialog page. then
i believe you will need to close the parents window.

-- bruce (sqlwork.com)
 
E

Eliyahu Goldin

Does
<input type="button" value="Ok" onclick="window.close();"/>
work?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
Eliyahu, it would. But how can I solve my problem of window not being
closed?

Eliyahu Goldin said:
Stan,

Would not it be easier to put the script straight to the <head> section
of the aspx page, setup the button's onclick event and stop worrying
about the script registration calls?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
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();" +
"}" +
"</script>";

if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
ClientScript.RegisterClientScriptBlock (Page.GetType(),
"CloseScript", Script);

===

When Ok button is clilcked, the window is flickering but does not close.

1. If window.showModalDialog is replaced with window.open, everything
works fine.

2. Similar code worked fine on 1.1 framework

3. There is a workaround to set window.opener to some value. I tried
that - didn't work

Thanks,

-Stan
 
S

Stan B

Yes, it does!
Eliyahu Goldin said:
Does
<input type="button" value="Ok" onclick="window.close();"/>
work?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
Eliyahu, it would. But how can I solve my problem of window not being
closed?

Eliyahu Goldin said:
Stan,

Would not it be easier to put the script straight to the <head> section
of the aspx page, setup the button's onclick event and stop worrying
about the script registration calls?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


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();" +
"}" +
"</script>";

if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
ClientScript.RegisterClientScriptBlock (Page.GetType(),
"CloseScript", Script);

===

When Ok button is clilcked, the window is flickering but does not
close.

1. If window.showModalDialog is replaced with window.open, everything
works fine.

2. Similar code worked fine on 1.1 framework

3. There is a workaround to set window.opener to some value. I tried
that - didn't work

Thanks,

-Stan
 
S

Stan B

It does work, but I still need close the window from the server because I am
saving user selection
in session.

So, when the script is injected by RegisterClientScriptBlock AND the window
is opened
via showModalDialog, it does not close.

Is there a workaround for this?




Eliyahu Goldin said:
Does
<input type="button" value="Ok" onclick="window.close();"/>
work?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
Eliyahu, it would. But how can I solve my problem of window not being
closed?

Eliyahu Goldin said:
Stan,

Would not it be easier to put the script straight to the <head> section
of the aspx page, setup the button's onclick event and stop worrying
about the script registration calls?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


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();" +
"}" +
"</script>";

if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
ClientScript.RegisterClientScriptBlock (Page.GetType(),
"CloseScript", Script);

===

When Ok button is clilcked, the window is flickering but does not
close.

1. If window.showModalDialog is replaced with window.open, everything
works fine.

2. Similar code worked fine on 1.1 framework

3. There is a workaround to set window.opener to some value. I tried
that - didn't work

Thanks,

-Stan
 
E

Eliyahu Goldin

I never liked the idea of script injection from the server. Instead of
passing javascript code from the server, almost always (there are
exceptions!) you can leave all scripts in the client code and pass from the
server a message instructing the client what to do. You can have a hidden
input control for passing this sort of messages:

<head>
<script>
function checkAction(){
switch(form1.inhAction.value){
case "CLOSE":
window.close();
break;
.....
}
form1.inhAction.value="";
}
</script>
</head>
<body onload="checkAction()">
<form id="form1" ...
....
<input type="hidden" runate="server" id="inhAction" />


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
It does work, but I still need close the window from the server because I
am saving user selection
in session.

So, when the script is injected by RegisterClientScriptBlock AND the
window is opened
via showModalDialog, it does not close.

Is there a workaround for this?




Eliyahu Goldin said:
Does
<input type="button" value="Ok" onclick="window.close();"/>
work?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
Eliyahu, it would. But how can I solve my problem of window not being
closed?

message Stan,

Would not it be easier to put the script straight to the <head> section
of the aspx page, setup the button's onclick event and stop worrying
about the script registration calls?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


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();" +
"}" +
"</script>";

if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
ClientScript.RegisterClientScriptBlock (Page.GetType(),
"CloseScript", Script);

===

When Ok button is clilcked, the window is flickering but does not
close.

1. If window.showModalDialog is replaced with window.open, everything
works fine.

2. Similar code worked fine on 1.1 framework

3. There is a workaround to set window.opener to some value. I tried
that - didn't work

Thanks,

-Stan
 
S

Stan B

It still does not close the form!

<script language=javascript>
function checkAction()
{
if (form1.inhAction.value == "C")
{
alert ("closing the form");
window.close();
}
form1.inhAction.value = "";
}
</script>

I set inhAction = "C" on the server and see "closing the form" popup, but
the form remains open...


Eliyahu Goldin said:
I never liked the idea of script injection from the server. Instead of
passing javascript code from the server, almost always (there are
exceptions!) you can leave all scripts in the client code and pass from the
server a message instructing the client what to do. You can have a hidden
input control for passing this sort of messages:

<head>
<script>
function checkAction(){
switch(form1.inhAction.value){
case "CLOSE":
window.close();
break;
.....
}
form1.inhAction.value="";
}
</script>
</head>
<body onload="checkAction()">
<form id="form1" ...
...
<input type="hidden" runate="server" id="inhAction" />


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Stan B said:
It does work, but I still need close the window from the server because I
am saving user selection
in session.

So, when the script is injected by RegisterClientScriptBlock AND the
window is opened
via showModalDialog, it does not close.

Is there a workaround for this?




Eliyahu Goldin said:
Does
<input type="button" value="Ok" onclick="window.close();"/>
work?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Eliyahu, it would. But how can I solve my problem of window not being
closed?

message Stan,

Would not it be easier to put the script straight to the <head>
section of the aspx page, setup the button's onclick event and stop
worrying about the script registration calls?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


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();" +
"}" +
"</script>";

if
(!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
ClientScript.RegisterClientScriptBlock (Page.GetType(),
"CloseScript", Script);

===

When Ok button is clilcked, the window is flickering but does not
close.

1. If window.showModalDialog is replaced with window.open, everything
works fine.

2. Similar code worked fine on 1.1 framework

3. There is a workaround to set window.opener to some value. I tried
that - didn't work

Thanks,

-Stan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top