Refresh parent page after Greybox close

6.8k views Asked by At

First of all, merry christmas to all of you :)

I have a blog, where people can make comments. I've now decided to put the "writecomments.aspx" file in a Greybox popup-window. It works, but I want to close the window from codebehind (or javascript) after the comment is written. And then I want to refresh the blog page (the parent page) to show the new comment.

This is the code that opens the greybox (writecomments.aspx) page:

<a href='WriteComments.aspx?BlogId=<%# DataBinder.Eval(Container, "DataItem.id") %>' rel="gb_page_center[500, 500]">Skriv kommentar</a>

In the writecomments.aspx file, I just have 2 textboxes and 1 button (save-button). How can I make the greybox window close itself, and then somehow refresh the blog.aspx? Or maybe just a specific updatepanel for the current comments?

Edit I got it working, I had to put this code in the codebehind, after the db-insert: Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.GB_hide();", true); And for the refresh of the parent page, I edited the gb_scripts.js file on line 12 from false to true: this.reload_on_close=true;

Merry Christmas! :)

EDIT AGAIN Actually, I modified it a bit, so, I put the gb_scripts.js file back to it's default state, and I just just the followig line of code in the WriteComments.aspx codebehind file, just after the db-insert:

Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.window.location.reload();parent.parent.GB_hide();", true);

Now, the Greybox is closing, and then, the blog page is refreshing, just like I want :)

5

There are 5 answers

0
Svein Erik On BEST ANSWER

I got the close function working! This is the code i had to use: Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.GB_hide();", true); Now I'll only have to refresh the parent page some way :)

0
Cody On

Here is the well explained ANSWER with easy steps : http://www.codeofaninja.com/2010/12/how-to-refresh-greybox-parent-page.html

10
Chandu On

Once the comment is successfully saved to DB, render the following javascript in the page:

window.opener.reload();
window.close();

In your WriteComments.aspx.cs once the save is successful add the code below to render the javascript in the HTML:

if (!IsClientScriptBlockRegistered("CloseMe"))
{
        String cstext1 = "<script type=\"text/javascript\">" +
            "window.opener.refresh(); window.close();</" + "script>";
        RegisterStartupScript("CloseMe", cstext1 );
}
0
steff_kukumicin On

As I am looking for a similar behavior, this is working in my case: http://www.phpfreaks.com/forums/index.php?topic=235378.0

"Pleas go through this file (gb_scripts.js) at line number 12 change 'this.reload_on_close=false;' to 'this.reload_on_close=true' and line number 67 change 'window.location.reload();' to 'window.location.reload(true);' and done « Last Edit: December 20, 2010, 04:38:42 AM by shashidharkumar »"

0
Kris On