How to open jQuery UI Dialog from codebehind

In this blog I will show how to open jQuery UI Dialog from codebehind. Basically what we are going to do is render the neccessary JS code for UI dialog from codebehind and when the page will render, it will show the dialog.

Here is Code:

<%@ Page Language="C#" AutoEventWireup="true"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<title>Ashish's Blog</title>
<link rel="stylesheet" href="" type="text/css" media="all" />
<script src="" type="text/javascript"></script>
<script src="" type="text/javascript"></script>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
StringBuilder sb = new StringBuilder();
sb.Append("$(function() { ");
sb.Append(" $('#dialog').dialog({");
sb.Append("    width: 350");
sb.Append(" });");
Page.ClientScript.RegisterStartupScript(typeof(Page), "myscript", sb.ToString(), true);
<form id="form2" runat="server">
<div id="dialog" style="display: none">
Welcome to Ashish's Blog
<asp:Button ID="Button1" runat="server" Text="Test" OnClick="Button1_Click" />


6 responses to “How to open jQuery UI Dialog from codebehind”

  1. hey i tried it the same way but it doesnt show me my code?
    i replace open jquery dilog code to some show and hide code but this doesnt fire it!

  2. Hi,

    I have tried this code and it is working perfectly only one issue i am facing when a pop up is open user can still work on the background page.Can you please add the code for disabled the background also.

Leave a Reply