简体   繁体   中英

  HTML markup renders not as expected

Two ASP.NET Web form pages:

Page1:

Type: Normal asp.net page, no containers or database binding controls

Rendered as: Content Content

Source (as shown in browser tool): <p>Content&nbsp;Content</p>

(Life is happy)

Page2:

Type: Database content, using DetailsView Control

Rendered as: Content&nbsp;Content

Source (as shown in browser tool): <p>Content&nbsp;Content</p>

I'm gonna be mad why does that happen! I want the &nbsp; to be a blank space!

Is that DetailsView charm or what!!

Appendix: Page2 markup

    <ItemTemplate>
    <%--Title--%>
    <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>'></asp:Label>

    <br />

    <%--Date--%>
    <asp:Label ID="lblDate" runat="server" Text='<%# Eval("date") %>'></asp:Label>

    <br />

    <%--Content--%>
    <p>
        <asp:Literal ID="lblContent" runat="server" Text='<%# Bind("content") %>' />
    </p>
</ItemTemplate>

Note that I tried the asp:Label and asp:Literal

Not sure why you would need two-way databinding on a label, so I would probably go back to using something like the following:

<%--Content--%>
    <p>
        <asp:Literal ID="lblContent" runat="server" Text='<%# System.Web.HttpUtility.HtmlEncode((string)Eval("content")) %>' />
   </p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM