In this article i will be explaining, How to open and close JQuery UI Dialog box on Button Click.
I have assumed that you have already created VS.Net Web Project and add JQuery UI reference into your web project. If you need help in adding JQuery UI into asp.net website, then please read my post on how to add JQuery UI into asp.net website
Create a asp.net content page and add following code
<asp:Button ID="btnOpenMe" runat="server" Text="Click Me to open Dialog box" />
<div id="dialog" title="My Dialog Title">
<p>This is My Dialog box Description/Content</p>
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#dialog").dialog({ autoOpen: false });
$("#<%=btnOpenMe.ClientID%>").click(
function () {
$("#dialog").dialog('open');
return false;
}
);
});
</script>
Understanding above code
1) I have declared a simple asp.net button control
2) $("#dialog").dialog({ autoOpen: false }); - By default dialog box will open on page load, this line will explicitly disallow dialog box to open on page load.
3) Inside button click event, I have wrote code to open JQuery UI dialog box.
$("#<%=btnOpenMe.ClientID%>").click(
function () {
$("#dialog").dialog('open');
return false;
}
);
Similarly if you want to close JQuery UI dialog box change below line with "close" rather than "open"
$("#dialog").dialog('close');
Watch out Live Demo
No comments:
Post a Comment