0

I want to close a ShadowBox popup when the user clicks a button. The popup is showing a separate page in an Iframe. This works fine with a clients-side event on the Cancel button control, e.g.

OnClientClick="javascript:parent.Shadowbox.close();"

The Ok button, however, has a server-side event, because data needs to be saved. When I define both an OnClick and the OnClientClick handler from above, the IFrame is closed and the server-side event handler never fires.

I tried to remove the OnClientClick event handler from the markup and to use the ClientScriptManager to accomplish this, as in

Page.ClientScript.RegisterStartupScript(this.GetType(),
  "Close", "parent.Shadowbox.close();", true);

Apparently because the buttons are in an UpdatePanel, the script does not get registered, and it does not appear in the Reponse stream. The IPanel stays open.

How can I do this?

tshepang
  • 12,111
  • 21
  • 91
  • 136
cdonner
  • 37,019
  • 22
  • 105
  • 153

1 Answers1

1

When you're using the MS AJAX controls, you need to register your scripts with the ScriptManager, not ClientScript.

womp
  • 115,835
  • 26
  • 236
  • 269
  • You mean like this: ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseScript", "window.close();", true); Makes no difference. – cdonner Sep 28 '09 at 15:54
  • Hmm. I'm interested now in why your original setup was preventing a postback. OnClientClick shouldn't prevent the postback if your javascript wasn't returning false.... – womp Sep 28 '09 at 16:20
  • I wrote a new method that explicitly returns true, still no postback. – cdonner Sep 28 '09 at 17:02
  • Injecting the script with the Scriptmanager is working. Not sure what was going on. – cdonner Sep 28 '09 at 17:23