【发布时间】:2016-12-08 09:10:19
【问题描述】:
我正在尝试从asp.net 代码隐藏向我的html 文档添加几个<img> 标签。我查看了Adding Html from Code Behind in Asp.net,它似乎是解决方案,但我不确定divcontrol.Controls.Add 如何确定它将开始添加html 的确切位置。据我所知,它位于 html 的末尾。我也找到了Write Html Markup from code behind in asp.net,但我也不知道怎么用。
这是我正在使用的html。如何添加我也包含的img 标签?:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Gallery</title>
<script type='text/javascript' src='/jquery-11.0.min.js'></script>
<script type='text/javascript' src='theme-tiles.js'></script>
</head>
<body>
<form id="form1" runat="server">
<h2>Tiles - Justified</h2>
<div id="gallery" style="display:none;">
</div>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#gallery").gallery({
tiles_type: "justified"
});
});
</script>
</form>
</body>
</html>
这是我需要在<div id="gallery">标签之间添加的<img>标签:
<img alt="img1"
src="images/thumbs/tile1.jpg"
data-image="images/big/tile1.jpg"
style="display:none"/>
</a>
这是我用来添加html的代码:
HtmlGenericControl divcontrol = new HtmlGenericControl();
divcontrol.Attributes["class"] = "sxro sx1co";
divcontrol.TagName = "div";
pnlUserSearch.Controls.Add(divcontrol);
Label question = new Label();
divcontrol.Controls.Add(question); // add to the new div, not to the panel
【问题讨论】: