Solved

Display server coded variables in jquery dialog

Posted on 2010-11-18
1
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

751 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