Creating a modal popup for asp.net users is always easy, its simply a modal panel, modal popup extender of asp.net ajax and all is done. but creating the modal popup that way will not work properly when you are having a following doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
and that's why we are looking into a simple method which uses javascript, and a tricky css to show the same kinda popup to work with the above doctype also.
here is how we can do so.
(1) add following css in your css or html document's style tag:
.graydiv { position: absolute; background-color: #5B5B5B; left: 0px; top: 0px; z-index: 10000; display: none; } .ModalBackground { background-color: black; filter: alpha(opacity=70); opacity: 0.7; }
(2) add following html markup at the end of your html document:
<div id="divg" class="ModalBackground graydiv"> </div> <div id="divSignin" style="border: '1px soild green'; display: none; z-index: 100002; width: 550px; position: absolute;"> <div style="text-align:right;height:100px;width:100px;background-color:White;border:solid 1px lightyellow"> This is a popup; <input type="button" value="Close Me" onclick="closePopup();" /> </div> </div>
(3) add following javascript in the script tag of your document or in your javascript file:
function closePopup() { document.getElementById("divSignin").style.display="none"; objDiv = document.getElementById("divg"); objDiv.style.display = "none"; return false; } function showPopup() { try { document.getElementById("divSignin").style.display="block"; objDiv = document.getElementById("divg"); objDiv.style.display = "block"; objDiv.style.width = document.body.scrollWidth; objDiv.style.height= document.body.scrollHeight; fnSetDivSigninLeft("divSignin"); } catch(e) { alert(e); } return false } function fnSetDivSigninLeft(oElement) { var DivWidth = parseInt(document.getElementById(oElement).offsetWidth,10) var DivHeight = parseInt(document.getElementById(oElement).offsetHeight,10) document.getElementById(oElement).style.left = (document.body.offsetWidth / 2) - (DivWidth / 2)+200; document.getElementById(oElement).style.top = (document.body.offsetHeight / 2) - ( DivHeight / 2); return false; }
and that's it, your popup is ready, the last step is to call this popup in your control and call its showPopup() event. here is a sample input button that calls the popup.
<input type="button" value="Show Popup" onclick="showPopup();" />
Note: If you want to show multiple popups, you can extend this code.
Note: You can use any color for modal background, for doing so, modify the change background color property of the ModalBackground class and try using the code.
Another simple way to implement this thing is to use JQuery Plugin but i don't know if they work well with HTML 4 or not. This one is a simple nice and clean approach to deal with modal poups.
happy coding :)