Nagamuneendrareddy E
Nagamuneendrareddy E

Reputation: 97

how to refresh parent window by using Javascript in .cs

How to refresh the parent window while closing the popup window(child window).

We are calling the java script functions in code behind to refresh the parent window by using page.ClientScript.RegisterStartupScript().But t is working fine in IE(internet explorer) but not working in Mozilla Firefox and Google Chrome.

In the Mozilla Firefox the pop up value is saving in the database but it is not updating into the parent page.If i did refresh manually the value is getting updating into the parent page. If i put debugger in RefreshPage()(javascript function) function in IE it is firing but not in Firefox.

The below code for call the javascript function in .cs class.

 page.ClientScript.RegisterStartupScript(this.GetType(), "PopupSave", "<script>javascript:alert('" + dsMessage.Tables[0].Rows[0]["ErrorMessage"].ToString() + "');window.open('','_self','');window.close();window.document.forms[0].submit();</script>");

The above code RefreshPage() is the javascript function to refresh the page

i.e.

function RefreshPage() { window.document.forms[0].submit(); }

Please help me i tried with different scenarios but no output.

instead of RefreshPage() i used different functions

like reload(),

window.opener.forms[0].submit(),

likewise but still no output anyone knows please help me.

Upvotes: 2

Views: 2994

Answers (3)

Amol Phule
Amol Phule

Reputation: 1

protected void ButtonClick(object sender, EventArgs e)
{
    string closeAndRefreshScript = @"<script type='text/javascript'>                                    
    window.opener.location.reload();
    window.close();
    </script>";
    base.Response.Write(closeAndRefreshScript);
}

Upvotes: 0

zeal
zeal

Reputation: 740

Before trying to make js calls between windows. Set 'document.domain' to the same value on both pages.

Upvotes: 0

Madhu Beela
Madhu Beela

Reputation: 2215

Try this function

on submit button click run this script

<script language='javascript'> window.opener.frames.location='somepage.aspx';window.close();</script>

this will help you !!!

Upvotes: 2

Related Questions