2

After searching the web for hours, I found some solutions regarding on how I can open a new Modal inside another Modal. But my requirement is kinda different. I want to use a somewhat "universal" modal form that will serve as a message box in my page (not the whole application, for the current page only). This message box will overlay all once being called/shown.

For example, I open a Modal form for my data entry, if I want to prompt a message to the user, I will pop another Modal form over the data entry form.

I am new to web programming so I don't know where my code went wrong or am I missing something.

Here's the code for my Designer:

<div class="modal fade" id="modAddBulletin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="top: 15%;" data-keyboard="false" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="modal-title" id="H2"><asp:Label ID="Label3" runat="server" Text="Add Bulletin"></asp:Label></h3>
                </div>
                <div class="modal-body" style="padding-bottom:0px">
                    <div="container">
                      <div>
                      <fieldset class="form-group">
                        <label for="txtTitle">Title</label>
                        <input id="txtTitle" runat="server" type="text" class="form-control"  />
                      </fieldset>

                      <fieldset class="form-group">
                        <label for="txtDescription">Description</label>
                        <textarea class="form-control" runat="server" id="txtDescription" rows="6" style="min-width:568px; min-height:151px; max-width: 568px;"></textarea>
                      </fieldset>

                      <fieldset class="form-group">
                      <asp:FileUpload ID="fleUpload" runat="server" data-filename-placement="inside" />
                      </fieldset>
                      </div>

                   </div>
                <div class="modal-footer">    
                        <asp:LinkButton ID="btnUpload" runat="server" CssClass="btn btn-success" Width="200px">
                        <span class="glyphicon glyphicon-cloud-upload"></span> Upload</asp:LinkButton>

                        <asp:LinkButton ID="btnCloseUpload" runat="server" CssClass="btn btn-default" Width="100px"> 
                        <span class="glyphicon glyphicon-share-alt" ></span> Back</asp:LinkButton>
                </div>
                </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->



        <%--// For Popup Message --%>


       <div class="modal fade" id="modalMsg"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="top: 30%;" data-keyboard="false" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-header" style="background:#4682b4; color:White;">
                    <h4 class="modal-title">Message</h4>
                </div>

                <div class="modal-body">
                    <asp:Label ID="lblErrorMsg" runat="server" Font-Names="Calibri" Font-Size="11pt"></asp:Label>
                </div>

            <div class="modal-footer">
               <asp:LinkButton ID="btnErrMsgClose" runat="server" CssClass="btn btn-primary" Width="100px" data-dismiss="modal">Close</asp:LinkButton>
            </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

Here's how I call them from code-behind:

ClientScript.RegisterStartupScript(Me.GetType(), "Show1", "<script> $('#modalMsg').modal('show');</script>")
ClientScript.RegisterStartupScript(Me.GetType(), "Show", "<script> $('#modAddBulletin').modal('show');</script>")

Here's the result:

FFFFFFF..

Thank you in advance.

Aethan
  • 1,986
  • 2
  • 18
  • 25
  • @SureshKamrushi, This post is quite old but I checked your link anyway. It's different from the said requirement here, what your code does is to close the previous modal and open a new modal which is the opposite of what I need. You can also check the image I attached in my post. Basically, a modal over modal. Thanks for the effort though! – Aethan Sep 05 '18 at 01:03

1 Answers1

20

You can use z-index to solve your problem.

var zIndex = 1040 + (10 * $('.modal:visible').length);
$(this).css('z-index', zIndex);
setTimeout(function() {
    $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
}, 0);

ONLINE DEMO

  • Hi, thanks for the response. But I think it still needs the _href_ fixed to the form to show the other modal form. I am calling mine from code-behind as a message box. Is there a flexible way to do it without the direct _href_ to the other form? – Aethan Jun 11 '16 at 02:31
  • @CrushSundae I found this [How to open a Bootstrap modal window using jQuery?](http://stackoverflow.com/questions/13183630/how-to-open-a-bootstrap-modal-window-using-jquery) may help you. – Trung Le Nguyen Nhat Jun 11 '16 at 02:37
  • The link doesn't work dude. What I am trying to do is to override all forms including previous modal with another modal. – Aethan Jun 11 '16 at 02:53