This post originated from an RSS feed registered with .NET Buzz
by Brendan Tompkins.
Original Post: An ASP.NET Modal Panel Control
Feed Title: Brendan Tompkins
Feed URL: /error.htm?aspxerrorpath=/blogs/brendan.tompkins/Rss.aspx
Feed Description: Blog First. Ask Questions Later.
One UI element that has always been tricky to create in ASP.NET
applications is the Modal Window. Often, applications will
present an entire page for simple property editing, in
situations where a modal window is a more elegant, and straight-forward
UI element. This is probably due mainly to the fact that there
are no intrinsic browser controls that work well for this, and are easy
to deal with on the server side.
If you do Web Application development, you've no doubt struggled
with the task of creating Modal forms. You have different options
for doing this, each with their own advantages and pitfalls.
Hosting your form in a new browser instance (window.open()) is
really a kludge, and many users have popup blocking software which
will break this approach. Using true Modal dialogs
(window.showModalDialog()) doesn't work well from within ASP.NET. Using
draggable DIV elements solves some of these issues, but has its own set
of problems. Dragging DIV elements involves using DHTML and JavaScript
and the script that you have to write to enable this can be tricky.
Toss browsers other than IE into the mix, and you've got even more
problems.
A big problem with this approach was that it relied on DHTML Behaviors which is
IE only and can cause problems with browsers running with a high
security level. After living with this solution for over a year,
and itâs drawbacks, I finally looked for a better way.
A Better Solution
Iâve come up with a new solution which uses standard ASP.NET Controls, DHTML and cross-browser JavaScript. ModalPanel
is implemented as a sub-classed ASP.NET Panel control. Since
itâs a Panel, it can be programmed in a way youâre probably already
familiar with if you do ASP.NET development.
This control adds a Title Bar, and optional close
button to the Panel. When the user drags the title bar, the
entire panel is dragged. It also uses cookies to remember itâs
position on postbacks and return visits to the page.
Thatâs it! If your have trouble getting it to drag properly,
or if it looks all funky, make sure you have your CSS stylesheet
referenced properly, and that you have the CSS classes defined as I
show in my example.