By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,979 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,979 IT Pros & Developers. It's quick & easy.

Unable to Close Popup window using ASP.Net

P: n/a
I am having a problem closing a popup window opened modally. When I
try to close the window (when the user hits save button and the data
has been processed), the Popup window opens as a full screen as a new
window. The original window plus the Modally opened Pop remain in a
separate window.

What I want to do is close the popup and return to the original window
with its view state maintained.

The control use to fire the popup window and the one to save the
changes need to be a web server control.
The popup window needs to be modal.
************************************************** *************************
The code I am using open the window with this control is:

private void butChangeOrder_Click(object sender, System.EventArgs e)
{
if (!IsClientScriptBlockRegistered("OpenPopup"))
{
RegisterClientScriptBlock("OpenPopup", "<script
language=\"javascript\">window.showModalDialog('Po pUpSortOrder.aspx',null,'font-size:10px;dialogWidth:43em;dialogHeight:40em,
toolbar=0,location=0,directories=0,status=no,menuB ar=1,scrollBars=no,resizable=no')</script>");
}
}

************************************************** *************************

The code that I am using to close the Popup window is:

private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );

if( !Page.IsClientScriptBlockRegistered ("ClosePopUp"))
{
RegisterClientScriptBlock("ClosePopUp", "<script
language=\"javascript\">function
CloseMe(){window.close();window.history.back(); };</script>");
}
butSaveOrder.Attributes.Add("onclick", "ClosePopUp()");
}
************************************************** *************************
Hopefully someone has a solution in this regard.

Cheers.

GrantS
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try to write out the script directly to the page after the save of data.

<code>
private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );
Response.Write("<script language=\"Javascript\">window.opener =
self;window.close();</script>");
Response.End();
}
</code>

The window.opener = self statement is to bypass the annoying message box
that IE throws at you when trying to close a window from javascript.

--
Patrik L÷wendahl
cshrp.net - " Elegant code by witty programmers "
cornerstone.se - " IT Training for professionals "
"GrantS" <su*************@hotmail.com> wrote in message
news:69*************************@posting.google.co m...
I am having a problem closing a popup window opened modally. When I
try to close the window (when the user hits save button and the data
has been processed), the Popup window opens as a full screen as a new
window. The original window plus the Modally opened Pop remain in a
separate window.

What I want to do is close the popup and return to the original window
with its view state maintained.

The control use to fire the popup window and the one to save the
changes need to be a web server control.
The popup window needs to be modal.
************************************************** ************************* The code I am using open the window with this control is:

private void butChangeOrder_Click(object sender, System.EventArgs e)
{
if (!IsClientScriptBlockRegistered("OpenPopup"))
{
RegisterClientScriptBlock("OpenPopup", "<script
language=\"javascript\">window.showModalDialog('Po pUpSortOrder.aspx',null,'f
ont-size:10px;dialogWidth:43em;dialogHeight:40em, toolbar=0,location=0,directories=0,status=no,menuB ar=1,scrollBars=no,resizab
le=no')</script>"); }
}

************************************************** *************************
The code that I am using to close the Popup window is:

private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );

if( !Page.IsClientScriptBlockRegistered ("ClosePopUp"))
{
RegisterClientScriptBlock("ClosePopUp", "<script
language=\"javascript\">function
CloseMe(){window.close();window.history.back(); };</script>");
}
butSaveOrder.Attributes.Add("onclick", "ClosePopUp()");
}
************************************************** ************************* Hopefully someone has a solution in this regard.

Cheers.

GrantS

Nov 15 '05 #2

P: n/a
> if( !Page.IsClientScriptBlockRegistered ("ClosePopUp"))
{
RegisterClientScriptBlock("ClosePopUp", "<script
language=\"javascript\">function
CloseMe(){window.close();window.history.back(); };</script>");
}
butSaveOrder.Attributes.Add("onclick", "ClosePopUp()");
}


Well, the button's onclick event should be wired to CloseMe(), not to
ClosePopUp (that's just the scripts key).

Another thing is that you call window.close() and then
window.history.back()... doesn't this mean you are trying to naviagate
backwards on a closed window?

Hope that helps,
-JG
Nov 15 '05 #3

P: n/a
N
You can try this

set <base target="_self"> for the popup window page and
then on click of the save button, save the data and then
do
RegisterStartupScript("winclose","<script>window.c lose
();</script>");.

Hope this helps,
N
-----Original Message-----
I am having a problem closing a popup window opened modally. When Itry to close the window (when the user hits save button and the datahas been processed), the Popup window opens as a full screen as a newwindow. The original window plus the Modally opened Pop remain in aseparate window.

What I want to do is close the popup and return to the original windowwith its view state maintained.

The control use to fire the popup window and the one to save thechanges need to be a web server control.
The popup window needs to be modal.
************************************************* ********* *****************The code I am using open the window with this control is:

private void butChangeOrder_Click(object sender, System.EventArgs e) {
if (!IsClientScriptBlockRegistered ("OpenPopup")) { RegisterClientScriptBlock ("OpenPopup", "<scriptlanguage=\"javascript\">window.showModalDialog ('PopUpSortOrder.aspx',null,'font-
size:10px;dialogWidth:43em;dialogHeight:40em,toolbar=0,location=0,directories=0,status=no,menu Bar=1,scr ollBars=no,resizable=no')</script>"); }
}

************************************************* ********* *****************
The code that I am using to close the Popup window is:

private void butSaveOrder_Click(object sender, System.EventArgs e) {
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings (); dtSave.SaveSortOrders (false,HiddenIds );
if( ! Page.IsClientScriptBlockRegistered ("ClosePopUp")) {
RegisterClientScriptBlock ("ClosePopUp", "<scriptlanguage=\"javascript\">function
CloseMe(){window.close();window.history.back (); };</script>"); }
butSaveOrder.Attributes.Add ("onclick", "ClosePopUp()"); }
************************************************* ********* *****************Hopefully someone has a solution in this regard.

Cheers.

GrantS
.

Nov 15 '05 #4

P: n/a
"Patrik L÷wendahl" <pa**************@csharpsweden.com> wrote in message news:<uk**************@TK2MSFTNGP10.phx.gbl>...
Try to write out the script directly to the page after the save of data.

<code>
private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );
Response.Write("<script language=\"Javascript\">window.opener =
self;window.close();</script>");
Response.End();
}
</code>

The window.opener = self statement is to bypass the annoying message box
that IE throws at you when trying to close a window from javascript.

--
Patrik L÷wendahl
cshrp.net - " Elegant code by witty programmers "
cornerstone.se - " IT Training for professionals "
"GrantS" <su*************@hotmail.com> wrote in message
news:69*************************@posting.google.co m...
I am having a problem closing a popup window opened modally. When I
try to close the window (when the user hits save button and the data
has been processed), the Popup window opens as a full screen as a new
window. The original window plus the Modally opened Pop remain in a
separate window.

What I want to do is close the popup and return to the original window
with its view state maintained.

The control use to fire the popup window and the one to save the
changes need to be a web server control.
The popup window needs to be modal.

************************************************** *************************
The code I am using open the window with this control is:

private void butChangeOrder_Click(object sender, System.EventArgs e)
{
if (!IsClientScriptBlockRegistered("OpenPopup"))
{
RegisterClientScriptBlock("OpenPopup", "<script

language=\"javascript\">window.showModalDialog('Po pUpSortOrder.aspx',null,'f
ont-size:10px;dialogWidth:43em;dialogHeight:40em,

toolbar=0,location=0,directories=0,status=no,menuB ar=1,scrollBars=no,resizab
le=no')</script>");
}
}

************************************************** *************************

The code that I am using to close the Popup window is:

private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );

if( !Page.IsClientScriptBlockRegistered ("ClosePopUp"))
{
RegisterClientScriptBlock("ClosePopUp", "<script
language=\"javascript\">function
CloseMe(){window.close();window.history.back(); };</script>");
}

butSaveOrder.Attributes.Add("onclick", "ClosePopUp()");
}

************************************************** *************************
Hopefully someone has a solution in this regard.

Cheers.

GrantS


Excellent! Thanks folks for the suggestions. I played with each of the
suggestions and turns out the the suggestion by N does what exactly
what I need. Bingo!
Code below with the last line being the one for others to use in this
situation.
Patrick's suggestion helped in that it did not throw up the extra
form, so I could have used it in the save and gotten rid of the close
button. The user could still close using the control box.
I played with the things Juan suggested but no go.

************************************************** *********************************************

private void butSaveOrder_Click(object sender, System.EventArgs e)
{
DataSavings dtSave = new CMSDataViewer.Utilities.DataSavings ();
dtSave.SaveSortOrders(false,HiddenIds );
/*
//Suggestion 1 (Patrick): Saves but does not close PopUp(At least
does not Open another window).
Response.Write("<script language=\"Javascript\">window.opener
= self;window.close();</script>");
Response.End();
//Suggestion 2 (JUan):My Original with Navigate before Close and the
ClosePopUp used consistently
if( !Page.IsClientScriptBlockRegistered ("ClosePopUp"))
{
RegisterClientScriptBlock("ClosePopUp", "<script
language=\"javascript\">function
ClosePopUp(){window.history.back();window.close(); };</script>");
}
butSaveOrder.Attributes.Add("onclick", "ClosePopUp()");
*/

//Suggestion 3 (N). This does the trick: - uses <base target="_self">
in page header:
RegisterStartupScript("winclose","<script>window.c lose();</script>");

}

************************************************** *********************************************
Thanks again. Grant
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.