简体   繁体   English

aspx页面的动态内容

[英]dynamic content for aspx page

I am trying to create some dynamic content for an aspx page and here is the direction that looks like it may work for me: 我正在尝试为aspx页面创建一些动态内容,这是它可能适合我的方向:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test123.aspx.cs" Inherits="Test123" %>

<%=_content %>

I have a protected variable in the code behind called _content that will supply the doc type and html contents which is coming from database. 我在名为_content的代码后面有一个受保护的变量,它将提供来自数据库的doc类型和html内容。

Any thoughts or comments? 有什么想法或意见吗? Is this a good and safe idea? 这是一个好主意吗? As long as I scrub the dynamic content. 只要我擦洗动态内容。

You could also use for HTML 5 documents unless you had a reason to support older versions. 除非有理由支持较早的版本,否则也可以使用HTML 5文档。 So that code would not have to be dynamic. 这样,该代码就不必是动态的。

I am not going to get into the reason why should or should not however your code would work just fine in Web Forms or MVC in terms of rendering HTML. 我不打算解释为什么应该或不应该在渲染HTML方面在Web窗体或MVC中使您的代码正常工作的原因。 Here is some sample code behind 这是一些示例代码

using System;
namespace StackOverFlowWebForm
{
    public partial class DemoForm : System.Web.UI.Page
    {
       protected string _content;
       protected void Page_Load(object sender, EventArgs e)
       {
          _content = "<h1>My Dynamic Title<h1>";
       }
    }
}

Followed by a sample page 后面是示例页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoForm.aspx.cs" Inherits="StackOverFlowWebForm.DemoForm" %>

<!DOCTYPE html>
<%=_content %>

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

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