简体   繁体   English

如何在ASP.NET Web表单中显示SQL数据库中的HTML内容

[英]How to Display Html content from sql database in asp.net webform

I want to display a blog page dynamically from my database,the row which I am retrieving contains html tags so it's displaying the raw html data along with tags,but i want to display it as a page.At present it is displaying like this. 我想从数据库中动态显示博客页面,我要检索的行包含html标签,因此它与标签一起显示原始html数据,但我想将其显示为页面。目前,它正以这种方式显示。

<p>In this article, we'll run down 10 tips you must note before you board a plane. <p>在本文中,我们将介绍10项登机之前必须注意的提示。 Remember, the primary goal of each of the items on this list is to benefit the traveler, but these tips will also make the whole in-flight experience a lot more comfortable and relaxed.</p> <h4>Take an Water bottle</h4> <p>Spending countless hours on the plane dehydrates your body and skin. 请记住,此列表中每个项目的主要目的都是使旅行者受益,但这些技巧也将使整个飞行中的体验更加舒适和放松。</ p> <h4>带水瓶< / h4> <p>在飞机上花费无数小时会使身体和皮肤脱水。 My tip is to take a stainless steel water bottle with you that you're able to fill up either just before boarding or on the plane by asking the flight attendant. 我的提示是随身带一个不锈钢水壶,您可以在登机前或乘飞机时向空乘人员注满水。 Most airports have water fountains near the boarding gates. 大多数机场的登机口附近都有喷泉。 Just make sure that your bottle is empty when you go through the screening points.</p> <img 穿过检查点时,只需确保您的瓶子是空的即可。</ p> <img

I want it do be displayed like a page with images being generated on its own. 我希望它确实像页面一样显示,并带有自己生成的图像。 I have tried using Literal Control but it's not working,I have google about this but didn't get a reasonable solution. 我尝试使用文字控制,但无法正常工作,我在Google上对此有所了解,但未获得合理的解决方案。

There are alot of ways to display the same in asp.net MVC but could'nt find anything for weforms 有很多方法可以在asp.net MVC中显示相同内容,但无法为weforms找到任何内容

I would be much obliged if any one could please help me out with this. 如果有人可以帮助我,我将倍感荣幸。

Have a markup like this: 有这样的标记:

<html>
    <body bgcolor="yellow">
        <%MyClass.MyFunction()%>
    </body>
</html>

Naturally, MyClass.MyFunction should return the html loaded from the database. 自然, MyClass.MyFunction应该返回从数据库加载的html。

Take one div in web page 在网页上取一格

  <div id="webcontent" runat="server"></div>

in Conding Side,assign your string or data fetched from DB to div. 在Conding Side中,将从DB提取的字符串或数据分配给div。

 string str =
    "Please enter your name:<br/>" +
    "<input type='text' name='userName'/>";

 webcontent.InnerHtml = str;

If you want to use javascript and deal with your div, dont forget to set its ClientIdMode to Static: 如果要使用JavaScript并处理div,请不要忘记将其ClientIdMode设置为Static:

  <div id="webcontent" runat="server" ClientIdMode="Static"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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