locked
How do I display a html string, set in code behind, on the .aspx page? RRS feed

  • Question

  • User562699594 posted

    I can't get the html I'm setting in code behind to render in the .aspx page.  It will display the variable, but as a string, not actually rendering the html.  HELP! 

    frown

    The code behind (.vb)

    Public isNCIA As String
    
    isNCIA = "<a href='FAQ.aspx' class='button'>FAQs</a>"
    

    And then displaying in the .aspx

    <div style="color:white; display: inline-block; height: 48px; width: 60px; padding-top: 22px; vertical-align: top;">
       <%--<a href="FAQ.aspx" class="button">FAQs</a>--%>
       <%= isNCIA %>
    </div>
    

    Friday, January 31, 2020 11:27 PM

Answers

  • User-1716253493 posted

    It's working for me, recheck typo

        <div>
            <%= isNCIA %>
        </div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 1, 2020 8:07 AM

All replies

  • User475983607 posted

    Use a literal control.

    <asp:Literal ID="Literal1" runat="server" Mode="PassThrough"></asp:Literal>
    Literal1.Text = "<a href='FAQ.aspx' class='button'>FAQs</a>"

    Friday, January 31, 2020 11:50 PM
  • User-1716253493 posted

    It's working for me, recheck typo

        <div>
            <%= isNCIA %>
        </div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 1, 2020 8:07 AM
  • User288213138 posted

    Hi id3ma,

    can't get the html I'm setting in code behind to render in the .aspx page.  It will display the variable, but as a string, not actually rendering the html

    You can also use the label control.

    The code:

    <asp:Label ID="Label1" runat="server" Text="FAQs"></asp:Label>
    
     Label1.Text = "<a href='FAQ.aspx' class='button'>FAQs</a>";

    Best regards,

    Sam

    Monday, February 3, 2020 4:23 AM
  • User562699594 posted

    Simply needed <%= instead of <%:

    Monday, February 3, 2020 4:02 PM