473,396 Members | 1,743 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,396 software developers and data experts.

Unable to Close Popup window using ASP.Net

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
4 34816
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
> 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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Colin Graham | last post by:
Hi guys, Just a quickie here that i hope someone can help me with. Basically i want stop the user from closing the popup window using the small x button in the top right hand corner. Im aware...
10
by: soup_or_power | last post by:
The pop up window has several checkboxes. I'm unable to access the checkboxes using the handle from window.open. Any way to do this? var display; function showSugg(but_id, sugg1, sugg2, sugg3,...
7
by: Drew Berkemeyer | last post by:
Hello, We have an application that we have written using ASP.NET. On one of our pages we open a popup window using javascript. The popup window has a save and a cancel button. Both of them are...
4
by: louise raisbeck | last post by:
I have this scenario (simplified) function addnewdata () { check for partial match already in db for information entered by user if (partialmatch succeeds) { open new window aspx page (using...
0
by: aiasso | last post by:
Hi All, Need big time help with this one. I'm using Forms Authentication with an ASP.NET (VB.NET) web app, and everything is fine until the client opens a popup window using javascript on the...
2
by: julie.siebel | last post by:
I KNOW this can't be as hard as I am making it. I have a travel client with two related websites. On the homepage of the new site (Call it "Site A") I am building for them, there is a link to a...
5
by: lindanr | last post by:
In ASP.NET 2005 I have an onblur="window.close()" javascript event in the <body> tag. When I click on the window's scrollbar, the window closes. The same code works fine in ASP.NET 2003. Any...
2
by: kurt sune | last post by:
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...
1
by: dittu | last post by:
How to close the popup window when submitting the form? I have a sample.jsp. In that page one button is there. when button pressed, open popup window contains one "text box" and one " submit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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.