Solved

Display server coded variables in jquery dialog

Posted on 2010-11-18
1
465 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

828 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