Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:00:55+00:00 2026-06-15T10:00:55+00:00

I’ve been working on a modal window for my site. I can’t get the

  • 0

I’ve been working on a modal window for my site. I can’t get the ajax one to work the way I want so I created it like this:

The modal window and background are just asp Panel controls that I’m hiding on page load (the code to do this, I agree is arb, but I haven’t managed to improve on it)

The following is the html (pre-render) for the modal:

<asp:Panel runat="server" ID="pnlModalbg" CssClass="modalbg"> </asp:Panel>
<asp:Panel runat="server" ID="pnlModal" CssClass="modal">
    <!-- Modal content goes here -->
    <p>Lorem ipsum dolor sit amet...</p>
    <!-- End Modal content -->

    <!-- Close button -->
    <div class="centeralign"><asp:Button runat="server" ID="btnCloseModal" Text="Close" CssClass="button" /></div>
    <!-- End close button -->
</asp:Panel>

Very simple. Now here’s the code that I’m using to show/hide it. The Panels above should be hidden on page load, and should then display on the GridView.RowCommand event. This works fine, but I doubt it’s the best way to do this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then

        pnlModal.Style(HtmlTextWriterStyle.Display) = "none"
        pnlModalbg.Style(HtmlTextWriterStyle.Display) = "none"
    End If

End Sub

Protected Sub gvAppointments_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvAppointments.RowCommand

    If e.CommandName = "ViewAppt" Then

        lblAppointmentId.Text = e.CommandArgument

        GetDetails()

        pnlModal.Style(HtmlTextWriterStyle.Display) = "block"

        pnlModalbg.Style(HtmlTextWriterStyle.Display) = "block"

    End If
End Sub

Protected Sub btnCloseModal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCloseModal.Click

    pnlModalbg.Style(HtmlTextWriterStyle.Display) = "none"
    pnlModal.Style(HtmlTextWriterStyle.Display) = "none"

End Sub

Now here’s the real problem. The CSS. This should position the modal window 150px from the top edge of the browser window and 450px from the left of the edge of the browser window regardless of screen resolution. It doesn’t. The horizontal positioning is different on every screen that I’ve test on.

Ideally, I’d like to use margins (preferably margin: 150px auto;) in the .modal class for positioning, but without the absolute positioning, it always displays packed in with the rest of the page content. Also, the .modalbg Panel appears over the modal window itself. Applying .modal {z-index: 9999;} and .modalbg {z-index: -1;} helps, but then the modalbg still appears to be behind other elements on the page and changing their z-index values doesn’t correct this.

.modal
{
    border: 2px solid #014073;
    border-radius: 5px;
    left: 450px;
    top: 150px;
    display: none;
    position: absolute;
    background: #fff;
    padding: 10px;
}

.modalbg
{
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: #000;
    -moz-opacity:.30;
    filter:alpha(opacity=30);
    opacity:.30;
    display: none;
}

I don’t mind having to change the display css in the server code, but any help with the css problems will be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:00:56+00:00Added an answer on June 15, 2026 at 10:00 am

    So after refining my modal and seeing as I’ve had no response to this question, here’s my current template for modal windows:

    The HTML

    <a href="#" class="showModal">Show Modal</a>
    
    <div class="modalbg" onclick="hideModal();">
    </div>
    <div class="modal">
        <!-- Content goes here -->
    
        <a href="#" class="hideModal">Hide Modal</a>
    </div>
    

    It’s very simple, just a couple of divs really. The one serving as the modal background is empty and the other one is the actual modal window which can be styled however you like. Also needed is a link or something that the user can click which will display the modal.

    I also added an onclick to the modal background so that if it ever gets clicked, it’ll hide the modal and let the user continue to use the rest of the site. I’ve seen some websites where this isn’t possible and it is quite intrusive really.

    The CSS

    .modal
    {
        box-shadow: 0 0 10px 2px #a1a1a1;
        border-radius: 5px;
        margin: 0 auto;
        display: none;
        position: absolute;
        background: #c1c1c1;
        padding: 10px;
    }
    
    .modalbg
    {
        height: 100%;
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #000;
        -moz-opacity:.30;
        filter:alpha(opacity=30);
        opacity:.30;
        display: none;
        z-index: 0;
    }
    

    As the question was about the css, here’s what I’ve got. basically, the modal background should span the entire browser window from the top left corner to bottom right. The modal is positioned at a 0 auto margin to center it correctly on the page (the top/bottom margin can be adjusted to your liking). This is where I was having problems when I asked the question but it shouldn’t be an issue with this template.

    And here’s the JQuery to make it all work

    var modalbg = $(".modalbg");
    var modal = $(".modal");
    
    $(".showModal").click(function() {
        modalbg.fadeIn(500);
        modal.fadeIn(500);
    });
    
    $(".hideModal").click(function() {
        hideModal();
    });
    
    function hideModal() {
        // It's important here to blank out any form fields you may have on the modal
        // use $("#field_name").text = "";
    
        modalbg.fadeOut(500);
        modal.fadeOut(500);
    }
    

    Mostly the JQuery just facilitates the display/hide of the modal. I’m sure there’s probably a way to improve on this, but it works perfectly fine as-is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.