首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

HtmlTextWriter显现 指点

2012-04-25 
HtmlTextWriter显现 请教高手指点上面用HtmlTextWriter呈现一张图1,中间显示部分html固定代码,接着又以Htm

HtmlTextWriter显现 请教高手指点
上面用HtmlTextWriter呈现一张图1,中间显示部分html固定代码,接着又以HtmlTextWriter方式显现一张图2,试了一个下午都没有实现,请知道的帮忙。谢谢了。
-------------------------------------------
我想要结果如下:

HTML code
<body>    <form id="form1" runat="server">    <div>    HtmlTextWriter writer显现方式-------下面显现图片1<% =writer.AddAttribute("url", "../xxx.gif");    writer.AddAttribute("width", "50");    writer.AddAttribute("height", "50");    writer.RenderBeginTag(HtmlTextWriterTag.Img);    writer.RenderEndTag();  %> 中间html代码<br>-------下面显现图片2<% =    writer.WriteBeginTag("img");    writer.WriteAttribute("alt", "A custom image.");    writer.Write(HtmlTextWriter.TagRightChar);    writer.WriteEndTag("img");    writer.WriteLine();  %>     </div>    </form></body>


[解决办法]
<form id="form1" runat="server">
<div>
HtmlTextWriter writer显现方式-------下面显现图片1

<%
System.IO.StringWriter stringWriter = new System.IO.StringWriter();

HtmlTextWriter writer = new HtmlTextWriter(stringWriter);

writer.AddAttribute("src", "http://dotnet.aspx.cc/Images/logoSite.gif");
writer.AddAttribute("width", "50");
writer.AddAttribute("height", "50");
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
 %> 

中间html代码<br>-------下面显现图片2
<% 
writer.WriteBeginTag("img");
writer.WriteAttribute("alt", "A custom image.");
writer.WriteAttribute("src", "http://dotnet.aspx.cc/Images/logoSite.gif");
writer.Write(HtmlTextWriter.TagRightChar);
writer.WriteEndTag("img");
writer.WriteLine();

Response.Write(stringWriter.ToString());
%> 
</div>
</form>

热点排行