Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 22nd, 2010, 01:59 PM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Question Popup & Parent window issue(critical)

Hi All

I am developing a web application where there is a parent window in which there are lot of textboxes and dropdowns and grid is also getting binded. I click on a button in parent window and open a popup window.

Code:
ScriptManager.RegisterStartupScript(this, GetType(), "open", "popupWin=window.open('Game.aspx?Type=" + "F0" + "&Empno=" + Empno + "&Location=" + Location + "&Vertical=" + Vertical + "&PrfCtrGrp=" + PrfCtrGrp + "&Department=" + Department + "&CostCenter=" + CostCenter + "&FromDate=" + FromDate + "&ToDate=" + ToDate + "','GAMEDETAILS', 'height=650, width=880,scrollbars=yes, resizable=yes');", true);
After the popup window gets opened, i select some records in gridview of the popup window and send it back across to parent page by using the following code:
Code:
ClientScript.RegisterStartupScript(typeof(Page), "myscript", string.Format("<script>CloseWindow('{0}');</script>", "AWD_Nomination_TOM.aspx?Mode=" + "AWD" + "&SessionId=" + SessionId +
                          "&AsLst=" + Session["ASLIST"]));
design page javascript in popup window
Code:
function CloseWindow(url)
{
    window.opener.location=url;
    self.close();
}
This works fine but what happens is that i loose the already entered textbox values etc. All entry made by the user in the parent window gets lost.
I dont want this to happen. Please advice what needs to be done and what i am missing?

Last edited by abhishekkashyap27; April 22nd, 2010 at 02:04 PM..
 
Old April 23rd, 2010, 12:03 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

The state of the controls is being lost. It sounds like you have ViewState turned off for your application. That's not necessarily bad. You probably just need to enable view state for this page. Just set EnableViewState="True" in the @Page directive. I would guess, that should do it.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old April 23rd, 2010, 12:37 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Nope, my view state is turned on. What happens is that the parent window page postbacks and load the entire controls again and inturn loosing all the entire values entered by the user earlier. Though i used session variable to store some of the control values(actually it worked) but this is crap as this is not the correct solution, what am i supposed to do if there are a lot of controls in the web page. is there any other way????
 
Old April 23rd, 2010, 11:25 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Isn't this by design?
Quote:
window.opener.location=url;
You're requesting a new URL which causes the browser to lose all control values and simply request a new page. Maybe you need to submit a form in the parent page instead?

Quote:
It sounds like you have ViewState turned off for your application. That's not necessarily bad. You probably just need to enable view state for this page.
With ASP.NET 2 / 3.5, this is not possible. If VIewState us turned off at the site level, you can't turn it on again at the page level. .NET 4 changes this behavior....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 14th, 2010, 08:13 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Imar

I cant use .NET 4.0, i have to develop in 2.0 only, tell me any solution to the problem. I am groping in darkness...
 
Old May 14th, 2010, 08:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Take another look at my original answer:

Quote:
You're requesting a new URL which causes the browser to lose all control values and simply request a new page. Maybe you need to submit a form in the parent page instead?
In other words, don't GET a new page, but POST to the existing one.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 14th, 2010, 09:45 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Imar

Can you elaborate what exactly you mean by 'Posting' to same page. From child window, i click on submit button so that it has to go and do a postback in the parent page which is in a different window and child window needs to get closed automatically. The code which i mentioned earlier works fine but the controls in the parent page lose their value, i.e. gridview , textboxes becomes null. What exactly i am doing wrong in the code???? what am i missing?
 
Old May 14th, 2010, 09:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
i click on submit button so that it has to go and do a postback in the parent page
That's exactly what I had in mind.

However, this:

Code:
 
window.opener.location=url;
reloads the parent page, rather than reposting it.

You could try using something like this:

window.opener.document.forms[0].submit();

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 14th, 2010, 10:12 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

window.opener.document.forms[0].submit();

The above code creates a postback to the popup page rather than doing it to the parent page! Sorry, just getting little impatient. The desire to solve the problem is burning me :)
 
Old May 14th, 2010, 10:17 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

http://www.webreference.com/js/tutorial1/opener.html
Quote:
The opener property sets or retrieves a reference to the window that created the current window.
In other words, this should submit the form in the window that created the popup - the parent window.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting values from Popup Window to Parent Window arnabghosh WinForms/Console Application Design 0 October 18th, 2009 12:51 AM
Sending values from Popup to Parent window arnabghosh ASP.NET 3.5 Professionals 1 October 17th, 2009 06:17 AM
Problem in closing the parent window from a popup rakesh.kashnia1 Javascript 4 July 9th, 2007 05:39 AM
Centering Popup window & Blur Parent window jkusmanto Javascript How-To 0 May 25th, 2007 03:19 AM
refresh the parent window when closing the popup ram_siddinen VS.NET 2002/2003 1 January 30th, 2004 04:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.