Open & Then Close Modal Popups In Code

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.

Who is Participating?
Rajar AhmedConnect With a Mentor ConsultantCommented:
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

Do you want the first Modal form to close? Or do you want to keep it "alive" when you show the "new" modal form?
EdAuthor Commented:
yes, i want the first modal to close and the 2nd one to open with a click of 1 button.
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.
Terribly sorry... I thought this was winForms...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.