[CLOSED] Get a Panel's dynamic HTML from code behind

  1. #1

    [CLOSED] Get a Panel's dynamic HTML from code behind

    Hello,

    I have a Panel where I set the HTML dynamically from code behind on the click of a button. Through another event I want to get the HTML, however the HTML attribute is always empty.

    Please see below an example. Click on the first button to add the HTML to the Panel. And then click on the second button to get the HTML.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <title></title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            [DirectMethod]
            public void AddHTML()
            {
                Panel1.Html = "<div>This is a test html</div>";
            }
    
            [DirectMethod]
            public void GetHTML()
            {
                string html = Panel1.Html; //returns empty string
            }
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Panel ID="Panel1" runat="server" Width="500" Height="500" Title="HTML Panel">
            </ext:Panel>
            <ext:Button runat="server" Text="Add HTML">
                <Listeners>
                    <Click Handler="App.direct.AddHTML();" />
                </Listeners>
            </ext:Button>
            <ext:Button runat="server" Text="Get HTML">
                <Listeners>
                    <Click Handler="App.direct.GetHTML();" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Also, I'd like to avoid using a Hidden field to store the HTML inside, as the generated html can get quite big.
    Last edited by Daniil; Nov 05, 2015 at 8:23 AM. Reason: [CLOSED]
  2. #2
    Hello again,

    I decided to skip getting the HTML from the code-behind and pass it directly to the method through JavaScript. However I faced a problem with passing an HTML string to code-behind, as the angle brackets from the tags were a problem. So I solved it using Ext.util.Format.htmlEncode and encoded the HTML string before passing it to the method.

    This thread can be closed.

Similar Threads

  1. Replies: 0
    Last Post: Jul 31, 2013, 3:23 AM
  2. [CLOSED] Dynamic HTML rendering in a Panel
    By vijay.sahu in forum 2.x Legacy Premium Help
    Replies: 10
    Last Post: Apr 05, 2013, 11:36 AM
  3. Replies: 2
    Last Post: Apr 12, 2012, 5:44 AM
  4. Replies: 1
    Last Post: Apr 11, 2012, 4:24 PM
  5. Replies: 2
    Last Post: Feb 19, 2009, 2:02 PM

Posting Permissions