Solved

Display server coded variables in jquery dialog

Posted on 2010-11-18
1
462 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:danielivanov2
1 Comment
 

Accepted Solution

by:
danielivanov2 earned 0 total points
ID: 34164507
Meanwhile I have found the answer, after checking the code once again. The correct serverside code attached, for future references.

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() {");

         sbScript.Append(@"$('#div2').append(");

         sbScript.Append("'" + sbContent + "');");

         sbScript.Append(@"$('#div2').dialog('open');});");

Page.ClientScript.RegisterStartupScript(this.GetType(), "script", sbScript.ToString(), true);

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now