Solved

Display server coded variables in jquery dialog

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

635 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