将本地html加载到asp.net中的div中

时间:2016-04-24 10:01:16

标签: javascript jquery html asp.net iframe

我想将LOCAL HTML PAGE加载到asp.net网络表单中的div中,并且没有必要使用空间解决方案。例如IFRAMEJQUERY.LOAD()等等。
我该怎么做? 注意:此HTML页面从数据库加载并上传到网络应用程序,因此我无法使用任何网址,例如www.foo.comhttp://localhost. 我很高兴听到最佳实践或任何想法或解决方案 感谢。

2 个答案:

答案 0 :(得分:0)

  1. 在表单中添加asp:Literal标记;
  2. 将您的HTML标记从数据库加载到本地变量
  3. 从本地变量
  4. 初始化Text标记的asp:Literal属性

    实施例

    形式:

    <asp:Literal ID="myHtmlContent" runat="server"></asp:Literal>
    

    代码背后:

        protected void Page_Load(object sender, EventArgs e)
        {
            string html = "<div style='color:red'><b>Hello</b></div>";
           // load HTML from DB insead
    
            myHtmlContent.Text = html;
        }
    

答案 1 :(得分:0)

最后在一些对话中使用哪个解决方案后,我用jquery.load()函数来做 上传我的HTML页面时,请使用以下功能调用它。

 <script>
        $(function () {
            $("#includedContent").load("../HtmlHolder/index.html");
        });

    </script>  

并将其放在此HTML标记中:

<div id="includedContent" class="reerer" style="width: 450px; height: 300px; border: 1px solid #808080; margin: 0px auto; overflow-y: scroll;"></div>

工作正常。