Wednesday, June 25, 2014

Show jQuery Modal Popup from Code behind (Server Side)

Introduction

Here I will explain how to show 
jQuery ui modal popup from code behind or open jQuery modal popup from server side in asp.net using c#vb.net.

Description
  
In previous articles I explained Show alert message from code behindjQuery show alert message while leaving from website
jQuery enable / disable controls on pagejQuery Countdown timer script example,jQuery Increase or Decrease font size of website and many articles relating to JQuery and asp.net. Now I will explain how to show jQuery ui modal popup from code behind or from server side in asp.net using c#,vb.net.

To show modal popup from code behind we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Show Modal Popup from code behind or server side</title>
<link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
function showmodalpopup() {
$("#popupdiv").dialog({
title: "jQuery Popup from Server Side",
width: 430,
height: 250,
modal: true,
buttons: {
Close: function () {
$(this).dialog('close');
}
}
});
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="popupdiv" title="Basic modal dialog" style="displaynone">
<b> Welcome to Aspdotnet-Suresh.com</b>
</div>
<asp:Button ID="btnShowModal" runat="server" Text="Show Popup" OnClick="btnShowModal_Click" />
</div>
</form>
</body>
</html>
In code behind we need to write the code like as shown below

C# Code


protected void btnShowModal_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "Show Modal Popup""showmodalpopup();"true);
}
VB.NET Code


Protected Sub btnShowModal_Click(ByVal sender As ObjectByVal e As EventArgs)
ScriptManager.RegisterStartupScript(Me, [GetType](), "Show Modal Popup""showmodalpopup();"True)
End Sub
Demo


No comments:

Post a Comment