ASP.net Literal or Page altering HTML string, causing formatting issues
We have a service that generates a report (using word templates and a 3rd party library), and then returns a string in HTML. While this HTML isn't great - its formatted correctly in this string.
We want this HTML to show up on a page - format intact. What we currently have done is set an ASP.net Literal's text element to this string.
While this works, I have noticed that it has reformatted the HTML string slightly. For the most part, it looks like it generated a bunch of new CSS classes, and a new style element in the HTML. This HTML does not exist in the string thats being returned. I could filter all of this back out, but wonder if there is a better way.
I assume that the Page itself is altering something.
What is the best way to display t开发者_如何学Gohis raw HTML back to the user? I can't directly use a Response.Write(string), because this page does have a few other controls on it.
Literal controls do not format their text values (AFAIK), so I would guess it's something else. Possibly a response filter (Request.Filter) which could be altering the page output? Another possbility may be that a containing control might be altering the value of its child controls (i.e. your literal) in it's custom rendering.
I've not heard of the Literal control behaving the way you have described and not seen it behave that way whenever I have used it but I have not attempted to output html in this way before.
An alternative could be to assign the html to a public page property in your code behind file and then use server side script tags in your aspx file to display the contents of this property:
<%=HTMLString %>
It was my own mistake, a setting on the third party library. I was saving my comparison page before it was messing with the CSS. Thank you for your helpful answers though - I thought I was loosing my mind!
精彩评论