Open & Then Close Modal Popups In Code

Posted on 2012-08-16
Last Modified: 2012-09-12
I have a button within a panel which is displayed in a modal popup.

What I am trying to do is when a user clicks the button it closes the current Modal Popup and opens a new one.

I've tried this which sort of works

    Protected Sub SignLink_Click(sender As Object, e As System.EventArgs)


    End Sub

Open in new window

When I say sort of works I mean that when I click the button the current modal does close but the new one does not open. However, when i click on the button to fire the original modal again I can see both modal popups.

Question by:edjones1
    LVL 13

    Expert Comment

    Do you want the first Modal form to close? Or do you want to keep it "alive" when you show the "new" modal form?

    Author Comment

    yes, i want the first modal to close and the 2nd one to open with a click of 1 button.
    LVL 13

    Expert Comment

    If you want it to close first, you should program a me.Close() in the Click event of the button.

    Once the form is closed the main program (which opened the first modal form) will continue to run. Here you can open your second modal form.

    If you want to open the second form "only" if the user clicks a button (i.e. not if he clicks the red X to close the form) you can create a private variable in the modal form, and a property and check it in the main program.

    Something like:
    In modalForm1:

    Private boolButtonClicked as Boolean=False

    Public ReadOnly Property ButtonClicked() As Boolean

        Return boolButtonClicked
    End Get

    End Property

    In modalForm1, when Button clicked

    In the main program
    myModalForm1.ShowModal() ' <<-- Shows the first modal form
    if myModal.ButtonClicked then ' <<-- Checks if the user clicked the button
    end if

    Hope it helps.
    LVL 18

    Accepted Solution

    pls check , whether you are following like below approach.
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="modalTwoOpenClose.aspx.vb" Inherits="JsJquery_modalTwoOpenClose" %>
    <%@ Register
        TagPrefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head id="Head1" runat="server">
        <style type="text/css">
            background-color: Black;
            filter: alpha(opacity=90);
            opacity: 0.8;
            background-color: #FFFFFF;
            border-width: 3px;
            border-style: solid;
            border-color: black;
            padding-top: 10px;
            padding-left: 10px;
            width: 300px;
            height: 140px;
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <asp:Button ID="Button1" runat="server" Text="Open Login Extendor" /><br />
            <asp:Label ID="UploadStatusLabel" runat="server"></asp:Label><br />
            <asp:HiddenField ID="dum" runat="server" />
    <cc1:ModalPopupExtender ID="LoginExtender" runat="server" PopupControlID="Panel1" TargetControlID="dum"
    <cc1:ModalPopupExtender ID="SignUpExtender" runat="server" PopupControlID="Panel2" TargetControlID="dum"
    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">
       Login Extendor
        <asp:Button ID="btnClose" runat="server" Text="Open Sign up " />
    <asp:Panel ID="Panel2" runat="server" CssClass="modalPopup" align="center" style = "display:none">
       Signup Extendor

    Open in new window

    Partial Class JsJquery_modalTwoOpenClose
        Inherits System.Web.UI.Page
        Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
        End Sub
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        End Sub
    End Class

    Open in new window

    LVL 13

    Expert Comment

    Terribly sorry... I thought this was winForms...

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now