PDA

View Full Version : [CLOSED] Get a Panel's dynamic HTML from code behind



FpNetWorth
Nov 04, 2015, 7:52 AM
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.

FpNetWorth
Nov 04, 2015, 9:50 AM
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.