内部html [英] Inner html
问题描述
我使用id和runat服务器创建了一个div标签,当使用div的内部html从服务器端(c#)插入代码时,将插入代码,但是未显示指定的图像.可能是什么问题?
例如
HTML代码:
----------
Hi,
I have created a div tag with id and runat server, when the code is inserted from the server side(c#) using inner html of div, the code is inserted, but the image specified is not shown. what could be the problem?
ex.
HTML Code:
----------
;
C#代码
-------
受保护的void Page_Load(对象发送者,EventArgs e)
{
如果(!IsPostBack)
{
GenerateHTMLCode();
}
}
公共无效的GenerateHTMLCode()
{
content_container.InnerHtml ="
;
C# code
-------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GenerateHTMLCode();
}
}
public void GenerateHTMLCode()
{
content_container.InnerHtml = "
"
"
" +
"" +
"<asp:image id="\"xyz\"" class="\"xyz\"" src="\"\\images\\Blue" hills.jpg\"="" alt="\"\""> " +
" Hi This is xyz!
";
}
";
}
推荐答案
asp:Image是服务器端标记. InnerHtml适用于HTML,不适用于ASP.NET. ASP.NET呈现为HTML.如果要插入图像,则必须使用HTML标记("img"是图像的HTML标记)来完成.
asp:Image is a server side tag. InnerHtml is for HTML, not for ASP.NET. ASP.NET renders into HTML. If you want to insert an image, you''ll have to do it using an HTML tag ("img" is the HTML tag for image).
这篇关于内部html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!