 |
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
|
|
|

April 22nd, 2010, 01:59 PM
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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..
|

April 23rd, 2010, 12:03 AM
|
Friend of Wrox
|
|
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
|
|
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.
|

April 23rd, 2010, 12:37 AM
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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????
|

April 23rd, 2010, 11:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

May 14th, 2010, 08:13 AM
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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...
|

May 14th, 2010, 08:23 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

May 14th, 2010, 09:45 AM
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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?
|

May 14th, 2010, 09:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

May 14th, 2010, 10:12 AM
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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 :)
|

May 14th, 2010, 10:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |