Mittal Patel
Mittal Patel

Reputation: 848

JavaScript: Not calling javascript function from the code behind

I have made one .aspx page to upload the image file.

Page 1 - from there I am opening Page2.aspx using window.open(small size like dialogbox) in js.

Then in Page 2 Javascript I have below WindowRefresh() function to refresh Page 1 and close Page 2(once file upload completes).

That is the reason I have used 'window.opener.location.href' to refer Parent Page(Page 1).

In Page 2 I have below Windowrefresh() function to refresh the parent window and it will close the Upload dialog window.

 function Windowrefresh() {
        if (window.navigator.appName == "Netscape") {
            window.opener.location.href = window.opener.location.href;
            window.opener.location.reload(true);
            self.close();
        }
        else if (window.navigator.appName == "Microsoft Internet Explorer") {
            window.opener.location.href = window.opener.location.href;
            window.opener.location.reload(true);
            window.close();
        }
    }

Now, I want to call this function from the code behind of Page 2 when one session variable has some value.

I tried below things.

ClientScript.RegisterStartupScript(this.GetType(), "key", "Windowrefresh();", true);

And,

Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "Windowrefresh()", true);

But it is neither refreshing Page 1 nor Closing Page 2.

I am not sure what is wrong in this.

Upvotes: 0

Views: 515

Answers (1)

Srikanth Kshatriy
Srikanth Kshatriy

Reputation: 444

do something like this.. I have not tested the code...... In the child window

<body onunload="refreshParent();">

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

  if (window.opener.progressWindow)

 {
    window.opener.progressWindow.close()
  }
  window.close();
}

close the child window when you have the session variable...(i dont know asp so cant help you with that syntax)

Upvotes: 0

Related Questions