Close colorbox on postback

2019-08-26 02:19发布

问题:

I am using colorbox to open a page in iframe. In that page i use ajax file upload to upload image asynchronously and then bind a datalist of new images.I have a button on the same page to close the iframe using this code

  protected void Cancel_Click(object sender, EventArgs e)
    { 
       ClientScript.RegisterClientScriptBlock(this.GetType(), "none", "<script>$(function(){closeIframe()});</script>"); 
    }

It works fine when i do not upload any image and click it. it closes color box but when i upload image and click it, then it takes me to a different page and gives following js error.

Uncaught TypeError: Cannot call method 'close' of undefined

This is the function which i use to close popup

<script>
function closeIframe() {
    parent.$.fn.colorbox.close();
}
</script>

回答1:

Can you post a link to your project? Without that, all we can do is guess. So here is a guess...

You say "it take me to a different page". If that page does not have ColorBox loaded, you will receive the error you are seeing.

Is that "different page" an iFrame of the original page? If it is not, you will received the error you are seeing.

To get started digging in, do this: * reproduce the error * on the page generating the error, inspect the DOM to see if ColorBox is loaded. * if it is not, rethink your page navigation or rethink how ColorBox is being used.

Post a link to your project for better help.

Regards.