CodeSnip: Refreshing a Parent Page from a Popup Page in VB.NET
page 1 of 1
Published: 03 Feb 2005
Unedited - Community Contributed
Abstract
I regularly find this question on many forums with long discussions about it, and I have found the following code with Javascript to be the best and easiest way to open a popup page, send a value, refresh the parent page, and close the popup child page.
by Sameer Lal
Feedback
Average Rating: 
Views (Total / Last 10 Days): 52677/ 47

The following is an example of one way to refresh the parent page from a child popup.  First off, you can add the following code on a button of the parent page to send the ID value as a cookie to the popup child page.

Response.Cookies ("ID").Value = TextBox1.Text
Dim sScript As String
sScript = "<script>window.open ('SurveyResults.aspx','','height=300, 
width=300, scrollbars=no') ;< /script>"
Response.Write (sScript)


This will open up SurveyResults.aspx page as a popup child page.  Then add the following code on the Page.Load event of SurveyResults.aspx page (the popup child page).
Private Sub Page_Load(ByVal sender As System. Object, ByVal e As System.EventArgs) 
Handles MyBase.Load
  'Put user code to initialize the page here
  If Not Page.IsPostBack Then
    Dim IDGet As Integer
    IDGet = Request.Cookies("ID").Value
     //with this IDGet, run the command and fill ds or whatever and then//
     Dim cScript As String
    cScript = "<script language='javascript'> opener.location.href = 'Survey.aspx'; </script>"
    RegisterStartupScript("parentwindow", cScript)
  End If
End Sub

To close the popup child page, you can have a button on SurveyResults.aspx page to add the following code.

Private Sub btClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles btClose.Click
  Response.Write("<script>window.close();</script>")
End Sub

That is all there is to it. I hope you will find this helpful.



User Comments

Title: Refreshing A parent page   
Name: S.Raj
Date: 2011-10-26 5:43:14 AM
Comment:
i need to know how the parent page refresh when popup window update the database and closed ???
Title: silverlight problem   
Name: refreshing takes to the login page in silverlight
Date: 2010-11-10 2:26:26 AM
Comment:
sir plz tell me its solution,i am stuck in this problem!!
Title: Mr   
Name: Ian
Date: 2010-09-21 8:26:55 AM
Comment:
Hello
Title: refresh   
Name: aaron
Date: 2010-05-12 3:41:48 PM
Comment:
Que significa (ID) IDGet = Request.Cookies("ID").Value

Ayudaaaaaaaa
Title: Refreshing Parent page   
Name: Chucky
Date: 2010-03-11 11:33:18 AM
Comment:
This really helped me. Thanks man.
Title: need help   
Name: Nitin Garg
Date: 2009-11-13 1:10:23 AM
Comment:
As i mention my problem below
"sir ,i need a popup in which i can change the view of popup
into to forms standered view or extended view and i can also want to .net control on to that popup (ex-asp:Button)
can you help me.help would be appriciated"
Any one who want to help me can contact me on my email
My Email Address:-Nitin202493@gmail.com or Nitin_talk_to@yahoo.co.in
Please help me its urgent
Title: C# Asp.Net   
Name: Nitin Garg
Date: 2009-11-13 12:28:49 AM
Comment:
sir ,i need a popup in which i can change the view of popup
into to forms standered view or extended view and i can also want to .net control on to that popup (ex-asp:Button)
can you help me.help would be appriciated
Thanks
Title: vb asp.net   
Name: krishna
Date: 2009-03-11 12:41:13 AM
Comment:
sir, i developed a project in asp.net in vb script. The problem is that the user can open directly any other web page other than start page by typing the page name after the specified url. how to restrict it. Even if the user gives otherd web page name it should display the start page only
Title: Close the window   
Name: Athula
Date: 2008-11-25 4:12:50 AM
Comment:
Thank you verymuch.
Title: Webcam live broadcast over internet   
Name: Lin
Date: 2008-06-05 8:48:39 PM
Comment:
Hi Sir,

I wrote a program using vb.net but need to stream it live over the internet for people to see. Can you help me. Thanks.

My email address is lin_qiwen_S@hotmail.com
Title: Live Broadcast   
Name: Ashutosh Kumar Jha
Date: 2008-03-27 6:13:58 AM
Comment:
Dear Sir,
I want To Develop A Live broadcast.where a user can share his
activity with many persons.
Email: jashutosh.software@gmail.com
Title: Broadcast   
Name: Ashutosh Kumar Jha
Date: 2008-03-27 3:54:03 AM
Comment:
Dear Sir,
I want To Develop A Live broadcast.where a user can share his
activity with many persons.
Title: Problem   
Name: MindGrill
Date: 2008-02-26 3:50:17 AM
Comment:
Hello,

I am getting the problem as when i close the form it doesn't gets away from memory and if it is called from another control with different set of data then also it pops up with old data.
any solution for this will be highly appreciated.

http://mindgrillq.blogspot.com

http://smsmantra.blogspot.com
Title: error   
Name: mhel
Date: 2008-02-21 8:40:48 AM
Comment:
i got an error saying : Microsoft JScript runtime error: 'opener.location' is null or not an object
Title: Greatt!!   
Name: simran
Date: 2008-01-11 12:04:43 AM
Comment:
It was great and worked perfectly..
thanks a lot....
Title: Nice Script   
Name: Kalai
Date: 2007-10-15 1:05:43 AM
Comment:
Hi,

The opener.location.href = 'Survey.aspx'; is the key,, I was racking my brain.. but it worked.. thankssssss
Title: Slight modification   
Name: TheLegend7
Date: 2007-06-27 10:00:45 AM
Comment:
Change RegisterStartupScript("parentwindow", cScript)
to
Page.ClientScript.RegisterStartupScript(Me.GetType(),"parentwindow", cScript)

and it works perfect!!

Thanks
Title: Mrs   
Name: Reji
Date: 2007-06-27 2:13:35 AM
Comment:
RegisterStartupScript is not working in .net2005
Title: not able to refresh   
Name: malli
Date: 2007-06-04 12:45:55 AM
Comment:
is it mandatory to pass the query..I am not able to refresh the page
Title: miss   
Name: soha
Date: 2007-05-21 8:46:22 AM
Comment:
Thankx
Title: More information needed in this article   
Name: Mohammed Mustafa
Date: 2007-05-07 3:28:30 AM
Comment:
It would be really great if u also provide the information for passing argument from one page to another page(pop-up).
Title: Refreshing a Parent Page from a Popup Page in VB.NET   
Name: sampa
Date: 2007-04-10 6:39:24 AM
Comment:
Hi All
I am new to this software and hardware,This parent window means ..is it belong to any of their house??Why parent can't close window?why he need child to close window..?may be child might be very small right?So its parent have to do it na....i donnow why u all passing comments on it?
Title: Refreshing a Parent Page from a Popup Page in VB.NET   
Name: Rick Quayle
Date: 2007-04-03 11:29:38 AM
Comment:
Just what i needed to know, thank you
Title: Consultant   
Name: Mike
Date: 2007-03-14 10:41:12 AM
Comment:
Doesn't work well for me. In addition to opening a popup it opens the same webform in a full size browser window.
Title: Developer   
Name: Jim
Date: 2006-12-23 3:26:18 PM
Comment:
Perfect, thanks!
Title: Software Developer   
Name: Suryakant
Date: 2006-08-17 9:17:55 AM
Comment:
It works. But i have a query.
I have a link button and a textbox in EditItemTempale of gridview to add/update records. when i click on linkbutton a pop up window opens and the user selects a value from the pop up window. then the pop up window should close and that selected value should appear in the textbox in editItemTemplate of gridview in parent window. hows is this poss.
Title: Passing values to Child Window   
Name: sai
Date: 2006-06-03 5:39:54 AM
Comment:
It works very fine. Thankyou very much for the informative article. This article solved my problem.

Regards
sai
Title: Senior Software Engineer   
Name: H.V.C.Raju
Date: 2006-05-05 12:43:11 AM
Comment:
Hi,
I have a problem while closing Pop-Up window and refreshing the parent page. Below is the Step:

1. First i am calling a pop-up window from the parent page and next i am calling one more pop-up window from the pop-up window itself.

2. My query is when i close the second pop-up window, the first pop-up window should refresh. and similarly when i close first pop-up parent page should refresh.

3. It shouldn't allow user to close Parent page before closing the both the pop-up window. Similarly it shouldn't allow user to close first pop-window before closing second pop-up.

Please help me for the same.

Thanks and Regards
Raju
Title: programer   
Name: Shibs
Date: 2006-04-19 2:06:28 AM
Comment:
Refresh is not working for me.. i am not able to refresh the parent page , while closing the pop up window.
Title: query string and pop windoows   
Name: Praveer Kumar
Date: 2006-03-27 3:32:58 PM
Comment:
What if I wish to use querystring in the button click event from the parent window? How to use query string ??
I have got better solution than cookies..
you have limitation to use the cookies that it can not be more than 20 per domain.
however u can also use multivalues cookies.

it is better idea to use sessions to send the value from the parent page and then Session.Remove("SessionName") on the page_load() of the child to remove it.
it is important to remove the sessions from the child page when it is received otherwise....session takes memory in the webserver and will not be efficient.
Title: child window   
Name: parag
Date: 2005-12-22 3:56:57 AM
Comment:
Mr. Lal, I have question. I have a list on my child window and I want the child to close when they select a any record and then populate a textboxs on the parent. I cannot seem to get the parent to refresh.Please help
Title: Programmer   
Name: Yashpal
Date: 2005-12-20 1:43:34 AM
Comment:
I encountered this problem ,I get this solution rearly this is good.
Title: CodeSnip: Refreshing a Parent Page from a Popup Page in VB.NET   
Name: Sean Lucas
Date: 2005-12-13 10:15:57 AM
Comment:
Mr. Lal, I have question. I have a calendar on my child window and I want the child to close when they select a date and then populate a textbox on the parent. I cannot seem to get the parent to refresh. I set the date chosen to a session variable and then the text box is set to the session. Please help
Title: Programmer   
Name: Viet
Date: 2005-10-24 2:51:35 PM
Comment:
Thank you. This article had solved my problem.
Title: Refreshing a Parent Page from a Popup Page in VB.NET   
Name: Donald Sanders
Date: 2005-07-31 7:28:04 PM
Comment:
This works fine. However, if you try it in VS.net 1.0 on the HTML page in between the two script tags (not using code behind) it does not work at all. You get weird errors. After you move it back to the code behind it works fine.
Title: Software Engineer   
Name: Hasham Qazi
Date: 2005-07-08 12:49:23 PM
Comment:
Excellent Code.This works really works very fine
Title: Software Engineer   
Name: Deepa
Date: 2005-03-03 12:29:03 AM
Comment:
I have a doubt. If I open child window for the second time, the Page_Load event of child winow is not getting raised. So, I'm getting the very old value again & again.
please give me a solution.
Title: a long way and using cookie.....   
Name: Ati
Date: 2005-02-16 9:46:57 AM
Comment:
I use simpler means. no problem refreshing the parent window....
document.contentwindow problem but handle it.
Title: Programmer   
Name: Scott
Date: 2005-02-14 2:46:29 PM
Comment:
I have a question, once I have opened the popup, I want to close the popup from the C# code that envoked it. Not by a user press. Example is a "please wait.." esp while retreiving data from the data server. While I can open the popup, I have not figured out how to close it prior to publishing a table view.
Title: Programmer   
Name: Ahmed
Date: 2005-02-14 7:30:58 AM
Comment:
Excellent. Though I agree with Paul, using cookie might not be the best option. Maybe querystring or session?
Title: I/T Architect   
Name: Paul
Date: 2005-02-07 8:24:45 AM
Comment:
Functional yes...best practice no. There are 9 ways of handling persistence in a .NET app. Although using a cookie will work, you have size issues as well as the field values will persist until the cookie expires.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-08-16 5:41:18 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search