How to display xml string in a Label?



I am trying to get my HTML method below, to encode the string and display it on label, but I keep getting a blank page, on the client-side.


I have checked the viewsource and it shows no HTML output their also.



public partial class About : Page
{
protected void Page_Load(object sender, EventArgs e, string data)
{
if (!IsPostBack)
{
string a = createXMLPub(data);
// Label1.Text = HttpUtility.HtmlEncode(a);
Label1.Text = Server.HtmlEncode(a);
}
}

public static string createXMLPub(string data )
{
XElement xeRoot = new XElement("pub");
XElement xeName = new XElement("name", "###");
xeRoot.Add(xeName);
XElement xeCategory = new XElement("category", "#####");
xeRoot.Add(xeCategory);
XDocument xDoc = new XDocument(xeRoot);
data = xDoc.ToString();
return data;

}


HTML



<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>


Please advice, to where I may be going wrong with this code. Many thanks


No comments:

Post a Comment