0

I have html strings stored in a database. These are labels and input fields but they also have aspx code in them. You know the nasty <%=%> stuff. In the view I use HtmlDecode(databaseString) on it and it renders the pure html but treats the aspx code as strings. Is there anyway that in the view this can be treated as aspx code?

This is basically a dynamic input form generator where we can define fields and then structure them into different forms for users to fill out. This helps us make it data driven instead of changing the code each time.

View example:

<% var incidentFields = (List<string>)ViewData["InputFields"]; %>

<%foreach(var fields in incidentFields){%>

   <%=System.Web.HttpUtility.HtmlDecode(fields) %>

<%}%>

The result:

enter image description here

user441521
  • 6,942
  • 23
  • 88
  • 160
  • I'm unaware of any functionality in Web Forms that would take ASPX markup as a string and then have it properly evaluated by the view engine. – mason Aug 05 '21 at 20:20
  • 1
    Reference to this [Render string containing razor-code](https://stackoverflow.com/questions/35913730/render-string-containing-razor-code-in-view) I hope That helps, Congrats. – Mina Shenouda Aug 06 '21 at 12:12
  • You can pull + load a whole page into a div on your existing page with jQuery.UI (a dialog). And the other page code will run. But just injecting markup - no, that will not work. – Albert D. Kallal Aug 06 '21 at 16:26
  • @AlbertD.Kallal The page code will always have html (with aspx markup in it) coming from a database table. Mina's comment above shows this can be done with Razor (although could be slow) so I'm just digging into if I can do the same with WebFormViewEngine instead of the razor view engine. – user441521 Aug 06 '21 at 16:49
  • 1
    ok - being pulled from a database as opposed to say pulling a whole existing page into one div on a page - yes, very different issue and problem - my bad. – Albert D. Kallal Aug 06 '21 at 16:56

0 Answers0