5 July 2006

Modal Pop-up Dialogs in ASP.NET

Posted by Mikhail Esteves under: C#; Tips .

Internet Explorer supports showModalDialog and most other browsers like Mozilla Firefox use modal=yes. Here’s a simple function that checks the browser type and returns appropriate JavaScript code to call a Modal Popup:

public static string ModalPopup (string URL, string Width, string Height)
{
  if (Page.Request.Browser.MajorVersion > 4 &&
      Page.Request.Browser.Browser == "IE")
  {
    return "window.showModalDialog('" + URL + "'," +
     null,'status:no;dialogWidth:" + Width +
     ";dialogHeight:" + Height + ";scroll:yes;" +
     "dialogHide:true;help:no');";
  }
  else
  {
    return "window.open('" + URL + "', null," +
     "'status=no,modal=yes,width=" + Width +
     ",height=" + Height + ",scroll=yes," +
     "scrolling=yes,scrollbars=yes');";
  }
}

An example call would be:

btnInfo.Attributes.Add("onclick", ModalPopup("info.aspx", "400px", "500px"));

Ofcourse, you may want to tweak the function to automatically center the dialog based on Width/Height or add Left and Top properties, etc.



Leave a Reply

Browse

Photography

Projects

Pages

Calendar

July 2006
M T W T F S S
« Jun   Aug »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Categories

www.flickr.com

Use OpenDNS