2

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?

Kev
  • 118,037
  • 53
  • 300
  • 385
Bastardo
  • 4,144
  • 9
  • 41
  • 60
  • Maybe this is too obvious, but don't you need a semicolon after the function call? "RefreshParent();" instead of just "RefreshParent()". – smelch Jun 01 '11 at 13:08
  • Well, @Smelch I tried that too, I am trying to figure out the problem for hours.As I alos mentioned in the question I used same methods, same sentences, same calls, on other pages and they are working perfectly but thanks for the idea. – Bastardo Jun 01 '11 at 13:11
  • Does `RefreshParent()` get hit at all? – Town Jun 01 '11 at 13:16
  • No Mr.Town that is the problem @Town – Bastardo Jun 01 '11 at 13:18
  • So this is in a popup and you are trying to refresh the parent page? – Bala R Jun 01 '11 at 13:22
  • Yes, Mr.R and yes I tried many things :).It seems like ScriptManager is what I needed in this situation.@Bala R – Bastardo Jun 01 '11 at 13:26

2 Answers2

3

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);
NakedBrunch
  • 48,713
  • 13
  • 73
  • 98
  • I have this `
    `
    – Bastardo Jun 01 '11 at 13:09
  • `RefreshParent()` should be a string. – Town Jun 01 '11 at 13:27
  • Thanks Alison. I did that a couple minutes ago when 1nstein suggested, and it s working thank you so much for your interest.However, in the other pages I mentioned and those having the same methods and working the same button is placed inside an UpdatePanel, too.And I had no problem with them.I do not understand why I had problem with this one. – Bastardo Jun 01 '11 at 13:30
0

Does the Button_KAYDET button placed in an UpdatePanel? if it is use the ScriptManager.RegisterStartupScript method instead of the ClientScript.RegisterStartupScript

Bastardo
  • 4,144
  • 9
  • 41
  • 60
Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
  • I checked that too, yes it is. – Bastardo Jun 01 '11 at 13:13
  • then use the ScriptManager.RegisterStartupScript method instead of the ClientScript.RegisterStartupScript – Yuriy Rozhovetskiy Jun 01 '11 at 13:18
  • 1
    Please post questions in the comments of the question. Leave answers to the solutions to the problem. Thanks. – Nathan Tregillus Jun 01 '11 at 13:24
  • Onestein we should hang out :D that is my answer "then use the ScriptManager.RegisterStartupScript method instead of the ClientScript.RegisterStartupScript " – Bastardo Jun 01 '11 at 13:25
  • But I still don't understand the difference, that Button_KAYDET is in an UpdatePanel on the pages these same methods are working, too. And they are ok, but this one is not. – Bastardo Jun 01 '11 at 13:29
  • This looks strange as an accepted answer! @1stein, can you edit your answer to actually include the answer? :) – Town Jun 01 '11 at 13:30