Search code examples
asp.netcssajaxcontroltoolkitmodalpopupextender

ModalPopupExtender doesn't work on IE6 frame layout


I'm using a "frame" layout similar to the one in this excellent answer: a div #top at the top of the page, a div#left on the left, and a div #main with the main content. The #top and #left divs contain navigation menus.

Now I want to use a popup div using the AjaxControlToolkit ModalPopupExtender inside the content (#main) div.

This works fine on IE8 (where #top, #left, #main all have position:fixed), but when I run it on IE6, the modal background only covers the #main div - I need it to cover the whole of the page including the #top and #left navigation divs.

Looking at the script for ModalPopupExtender, it appears to be searching up the parent hierarchy until it finds a parent with position relative or absolute. And in the IE6 rendering, the #main div has position:absolute because position:fixed is not supported, which I guess explains what is happening.

Any suggestions for the best/easiest way to get this working properly on IE6? Ideally without modifying the ModalPopupExtender code, but I'll do this if I have to and it's the best solution.


Solution

  • I've implemented a variant of the solution in this answer, which appears to solve the problem:

    • For IE6, conditionally make the #main div position:static with margin-left equal to the width of the #left div. Unfortunately margin-top doesn't seem to work in IE6, so...

    • For IE6, conditionally add an empty div with the id ie6-spacer before the main div.

    • Set the height of the ie6-spacer div to the same height as the #top div.

    This appears to the trick.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>'Frames' using &lt;div&gt;s</title>
      <style type="text/css">
        * {
          margin: 0;
          padding: 0;
        }
    
        html, body {
          height: 100%;
          overflow: hidden;
        }
    
        #top, #left, #main {
          position: fixed;
          overflow: hidden;
        }
    
        #top {
          top: 0;
          width: 100%;
          background-color: #ddd;
          height: 100px;
        }
    
        #left {
          left: 0;
          top: 100px;  /* move everything below #top */
          bottom: 0;
          background-color: #bbb;
          width: 120px;
        }
    
        #main {
          top: 100px;
          left: 120px;
          bottom: 0;
          right: 0;
          overflow: auto;
        }
      </style>
      <!--[if IE 6]>
      <style>
        #top, #left {
          position: absolute;
        }
    
        #ie6-spacer {
            height:100px;
        }
    
        #left {
          height: expression((m=document.documentElement.clientHeight-100)+'px');
        }
    
        #main {
          margin-left:120px;
          height: expression((m=document.documentElement.clientHeight-100)+'px');
          width: expression((m=document.documentElement.clientWidth-120)+'px');
        }
      </style>
      <![endif]-->
    </head>
    <body>
      <div id="top">Title<br /></div>
      <div id="left">LeftNav<br /></div>
      <!--[if IE 6]>
      <div id="ie6-spacer"></div>
      <![endif]--> 
      <div id="main">
        <p>
            Lorem ipsum ...<br />
            <!-- just copy above line many times -->
        </p>
      </div>
    </body>
    </html>