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

5
  • 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. Commented Aug 5, 2021 at 20:20
  • 1
    Reference to this Render string containing razor-code I hope That helps, Congrats. Commented Aug 6, 2021 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. Commented Aug 6, 2021 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. Commented Aug 6, 2021 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. Commented Aug 6, 2021 at 16:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.