在ASP.Net网页中创建HTML标记

问题描述 投票:0回答:1

因此,我正在建立一个博客,有时会包含用于演示基本数论算法的代码,有时还包括不同食物菜肴的图像。我正在使用ASP.Net网页。我不知道如何将博客显示为html,因为写作,代码和图像的顺序会有所不同。例如,我们是否将博客与标签一起存储并直接读入:<%= GetBlog()%>或使用自制标签存储博客并解析它们,然后使用以下方法创建某种循环:<%...% >我真的很喜欢这个网站的格式,我们可以输入写作

和代码和图像是否有一个模式,是实现我所描述的理想的模式?

html asp.net
1个回答
1
投票

例如,在您的C#代码后面:

protected void Page_Load(object sender, EventArgs e)
{
    this.Literal1.Text = "my paragraph here";
    this.Image1.ImageUrl = "http://simpleicon.com/wp-content/uploads/smile.png";
    this.Image1.Height = 20;
    this.MyCodeControl.InnerText = "my code here";
}

在.aspx文件中,您有:

<p><asp:Literal ID="Literal1" runat="server"></asp:Literal></p>
<asp:Image ID="Image1" runat="server" />
<code id="MyCodeControl" runat="server"> </code>

由于Internet浏览器不了解Asp和C#,因此该代码在服务器上运行并进入此Html:

<p>my paragraph here</p>
<img id="Image1" 
     src="http://simpleicon.com/wp-content/uploads/smile.png"
     style="height:20px;" />
<code id="MyCodeControl">my code here</code>

我不知道什么服务器端控件生成codep Html标签,所以我添加了runtat="server"属性的普通Html标签。这允许我在后面的C#代码中访问控件。

另请参阅如何使用更复杂的控件,如Repeater和ListView。

© www.soinside.com 2019 - 2024. All rights reserved.