Reputation:
When I want to write the result of a function as-is onto a masterpage or aspx page without a span container created by a label, I use a code render block. It works, and it does the job reliably.
My question is whether there is another way to achieve this exact outcome without use of an inline code render block? Does such an alternative exist for asp.net 4.0 and above?
Here is an example of how I use a code render block, where str_Sitemap is a public property as string in my code behind.
I found this method on MSDN: Code Render Blocks, and the page did not say "this is bad practice." At the same time, I have a personal (perhaps irrational) dislike of inline blocks and try to use alternatives as much as possible. At the moment, I do not have an alternative for producing this precise result.
<div id="div_Navigation">
<nav>
<% Response.Write(str_Sitemap)%>
</nav>
</div>
Upvotes: 1
Views: 375
Reputation: 55308
Use asp:Literal
<div id="div_Navigation">
<nav>
<asp:Literal ID="Sitemap" runat="server" />
</nav>
</div>
This is how to assign a value to that literal in a sub.
Private Sub LoadPage(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cm_Sitemap = New Clean_Menu("menu_Main", "sm sm-blue")
Me.Sitemap.Text = cm_Sitemap.Get_Sitemap
End Sub
Upvotes: 1