views:

261

answers:

1

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?

+1  A: 

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

womp
You mean like this:ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseScript", "window.close();", true);Makes no difference.
cdonner
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
I wrote a new method that explicitly returns true, still no postback.
cdonner
Injecting the script with the Scriptmanager is working. Not sure what was going on.
cdonner