Link to home
Start Free TrialLog in
Avatar of danielivanov2
danielivanov2Flag for Romania

asked on

Display server coded variables in jquery dialog

Hello, I need to display in a jquery dialog some static text plus dynamic text (based on values computed on server side in C#). The div dialog is made "onthefly", I dont need it in DOM after closing the dialog.
How should the server side be implemented? The dialog is diaplayed but with no content
I have put some code attached.
Thanks
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="../Scripts/jquery-142min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-ui-182custommin.js" type="text/javascript"></script>
    <link href="../CSS%20Files/jquery-ui-182custom.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function() {
            $("#div1").append("<div id='div2'></div>");
            $("#div2").dialog(
                 {
                     bgiframe: true,
                     autoOpen: false,
                     modal: true,
                     title: 'Title: ',
                     buttons: [
                        {
                            text: "Ok",
                            click: function() { $(this).dialog("close"); }
                        }
                            ]
                    });
        });         
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="div1">
        <asp:GridView ID="test" runat="server"></asp:GridView> 
    </div>
    <div>
        <asp:Button ID="but1" runat="server" Text="showdialog" OnClick="ButtonClick" />
    </div>
    </form>
</body>
</html>

protected void ButtonClick(object sender, EventArgs e)
    {          
         System.Text.StringBuilder sbContent = new System.Text.StringBuilder();
         int fup=1500;
         sbContent.Append(@"<ul><li>FUP: ");
         sbContent.Append(fup.ToString());
         sbContent.Append(@"</li></ul>");
         System.Text.StringBuilder sbScript = new System.Text.StringBuilder();
         sbScript.Append(@"$(function() {");
        //$('#div2').dialog('open');});");
         sbScript.Append(@"$('div2').append(");
         sbScript.Append(sbContent + ");");
         sbScript.Append(@"$('#div2').dialog('open');});");
         //I need to append sbScript to RegisterStartupScript command
         //Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "$(function() {$('#div2').dialog('open');});", true);
         Page.ClientScript.RegisterStartupScript(this.GetType(), "script", sbScript.ToString(), true);
     
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of danielivanov2
danielivanov2
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial