The JavaScript function does not work

advertisements

I have this line in a button click method on my aspx.cs file

ClientScript.RegisterStartupScript(this.GetType(),
                                   "RefreshOpener",
                                   "RefreshParent()",
                                    true);

I have this code on aspx file

function RefreshParent() {
                   window.opener.location.href = window.opener.location.href;

        }

When I debug th code, it comes to this line ClientScript.RegisterStartupScript(this.GetType(), "RefreshOpener", "RefreshParent()", true); but does not go to aspx file to run the JS code.

The most frustrating part is I have used the same things on some other pages with the same methods and they worked but this time it is not.

This is the button mentioned

<asp:ImageButton ID="Button_KAYDET"
                 runat="server"
                 CausesValidation="False"
                 ImageUrl="~/images/butonlar/kucuk/kaydet.jpg"
                 OnClick="Button_KAYDET_Click"
                 meta:resourcekey="Button_KAYDETResource1" />

Any ideas?


If the button is placed inside of an UpdatePanel then you'll need to use the ScriptManager.RegisterStartupScript method (MSDN Link).

Your code should look like:

ScriptManager.RegisterStartupScript(this, this.GetType(), "RefreshOpener","RefreshParent()", true);