Click here to Skip to main content
15,888,051 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi friends,

I am new to Jquery. I want to open a modal pop up window on click of a button. The Gridview will be filled by some data. if the gridview contains some data, then that data i want to display in modal pop up.If the gridview doesn't contains data, then I want to display a message box saying that 'The Data is not available'. I am able to display a dialog box on load of the page but not on click of a button. I am not able to apply proper CSS like display block and none.

Help me to solve the problem.....
Posted
Updated 27-Jul-16 11:43am

Hi, hope my explanation will help you.

First of all make sure that you have referenced to jquery libraries: for example

XML
<head>
        <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js"></script>
        <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.min.js"></script>
        <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css" />
    </head>



Then in your page declare some pop-up dialog:

XML
<div id="CheckMessagesDialog" style="display: none">
</div>
<button id="testBtn">Press me</button>


On page ready event handler add few initialization lines:

JavaScript
$(document).ready(function () {
$('#MessagesDialog').dialog({
				autoOpen: false, modal: true,
				width: 450, height: 400,
				hide: "explode", show: "blind",
				closeOnEscape: true,
				buttons: {
					"Close": function () {
						$(this).dialog("close");
					}
				},
				open: function (event, ui) {
				}
			});

}

$('#testBtn').click(function(){
if ($("#MessagesDialog").dialog("isOpen") === true) {
    $("#MessagesDialog").dialog("close");
}
$("#MessagesDialog").dialog({ title: "Hello tittle" });
$("#MessagesDialog").dialog('open');
});
 
Share this answer
 
I have written an article on how to load dynamic content into a jQuery Modal dialog window.

[Take a look at this article ^]

You will get a basic idea as to how to accomplish this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900