Script for a close button which will work both for colorbox popup and normal popup in a asp.net and vb.net web application

I have a page which opens as a popup from two different area.

In the first area it opens as a colorbox popup.

And from the second one it opens inside another simple javascript popup.

The problem is the page was previously designed as a colorbox popup.

And the close button designed for the page works only when it opens as colorbox popup.

<a href="javascript:parent.$.colorbox.close();" class="btn" title="Close Window">Cancel</a>

But the close button doesnot work when it opens inside another simple popup. I normally use the following line of code for the close button of normal simple popup

<a class="btn" href="javascript:window.close();">Close</a>

but that doesnot work when the popup opens as a colorbox popup.       Is there any script that will work in both cases?

I have tried to close the popup window via vb.net by using the following code .

asp.net line of code 

<asp:LinkButton runat="server" EnableViewState="false" ID="uxClose"
            Text="Close Window via Asp" CssClass="btn" />

VB.net code

  Protected Sub uxClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxClose.Click
        If Not Page.IsValid Then Exit Sub
        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CloseWindowScript", "window.close();", True)

   End Sub

that does not work.

I have also tried

 Protected Sub uxClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxClose.Click
        If Not Page.IsValid Then Exit Sub
       Me.close()
   End Sub

but that gives error message 

I will appreciate your kind co operation

Thank you

Hi bashabi,

Thanks for your post.

As for your problem, I have some questions.

  1. Would you like to close the popup window or parent window?
  2. The close button is in the parent window or popup window.
  3. Could you show us more code to help us reproduce your problem?

Best Regards,

Fei Han

Hi 

Thanks for your reply. I want to close only the popup window and that close button also in the popup window.

As I said in my question this popup window opens from several area of the parent window .  From some area it opens as a color box popup. and there are some area it opens inside another normal popup page and thus it opens as a normal popup.

————————

To explain more 

Suppose : The popup window is n_pop_up.aspx . If the n_pop_up.aspx  page opens from list.aspx page which is a page in parent window;  it opens as a colorbox popup.

The code in list.aspx page to open  n_pop_up.aspx  page  is 

<%@ Page Title="" Language="VB" MasterPageFile="~/_resx/E4.master" AutoEventWireup="false" CodeFile="new.aspx.vb" Inherits="E4_Jobs_Details_Interview_New" ValidateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
<input type="hidden" name="vid" id="vid" value="<%= Vacancy.ID.ToString()%>" />


     <a href="#" id="saveInt" class="btn">Continue</a>

</asp:Content>

<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="ScriptContent">


    <script type="text/javascript" charset="utf-8">

     $(function () {

                    if((parseInt(r.d))>0) {

                             var commUrl = "n_pop_up.aspx?templatetypeid=1&communicationtemplateid=" + $('#intTemplate').val() + "&applicationid=" + applicants.join() + "&interviewid=" + r.d;
                             $.colorbox({ width: '900px', height: '90%', iframe: true, href: commUrl, open: true, overlayClose: false });
                        }
               return false;

    });

    </script>
</asp:Content>

There is another popup suppose its name is d_popup.aspx which is opened as a normal popup (when i say normal popup that is that popup is opened via  window.open() method). and the code to open that popup is following,

        function openpopup() {
                 var CURL = 'd_popup.aspx?i=' + application.Id;
                 window.open(CURL, '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=820,height=600,left = 560,top = 240');

        }

and the n_pop_up.aspx is also linked in d_popup.aspx page and when the link is clicked its opens inside the d_popup.aspx page. 

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
        <div class="btn-group">
             <button class="btn dropdown-toggle" data-toggle="dropdown">
                    <i class="icon-cog"></i>                                                                                                </button>
                   <ul class="dropdown-menu pull-right">
                      <li class="dropdown-submenu">
                           <a href="n_pop_up.aspx">Communication</a>                                                                            
                      </li>
                                                                                         
                                                                                         
                    </ul>
           </div>
</asp:Content>

And when the n_pop_up.aspx page is opened inside d_popup.aspx page that opens as a normal popup. 

The following close button in the n_pop_up.aspx page works when the page opens as a color box popup

        <a href="javascript:parent.$.colorbox.close();" class="btn" title="Close Window">Cancel</a>

And the following close button in the n_pop_up.aspx page works when the page opens as a normal popup

                <a class="btn" href="javascript:window.close();">Close</a>

but none of the above works for both case.  I want something that will serve both cases.

————–

I hope I have been able to make the situation  clear to you.

looking forward to your reply

Thanks

Leave a Reply