当前位置: 代码迷 >> ASP.NET >> 重写 Render(HtmlTextWriter writer) 方法产生的有关问题?
  详细解决方案

重写 Render(HtmlTextWriter writer) 方法产生的有关问题?

热度:6442   发布时间:2013-02-26 00:00:00.0
重写 Render(HtmlTextWriter writer) 方法产生的问题???

protected   override   void     Render(HtmlTextWriter   writer)
        {
                writer.Write(@ " <html> ");
                writer.WriteLine();
                writer.Write(@ " <head> ");
                writer.WriteLine();
                writer.Write(@ " </head> ");
                writer.WriteLine();
                writer.Write(@ " <title> ");
                writer.WriteLine();
                writer.Write( "测试链接数据库时的效率 ");
                writer.Write(@ " </title> ");
                writer.WriteLine();
                writer.Write(@ " <body> ");
                writer.WriteLine();
                ShowTable(writer);
                writer.Write(@ " </body> ");
                writer.WriteLine();
                writer.Write(@ " </html> ");
                writer.Close();
                base.Render(writer);
        }

生产表格成果,但在查看该网页的源文件时,原来的这个页面的前台标签并没有被清空?请问这是什么原因,应该怎么处理?
源文件:
<html>
<head>
</head>
<title>
测试链接数据库时的效率 </title>
<body>
....
</body>
</html>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head> <title>
无标题页
</title> <link   href= "App_Themes/gridview/gridview.css "   type= "text/css "   rel= "stylesheet "   /> </head>
<body>
        <form   name= "form1 "   method= "post "   action= "dynamicTable.aspx "   id= "form1 ">
<div>
<input   type= "hidden "   name= "__VIEWSTATE "   id= "__VIEWSTATE "   value= "/wEPDwUJNzgzNDMwNTMzZGSqGnvZWg2k52Y8hPUMkkmvsgVRjQ== "   />
</div>

        <div>

        </div>
        </form>
</body>
</html>
如何除掉后面这一段html标签?

------解决方案--------------------------------------------------------
把那句base.Render(writer)去掉看看!
------解决方案--------------------------------------------------------
HtmlTextWriter还有其他的方法
比如writer.RenderBeginTag(HtmlTextWriterTag.Html);
------解决方案--------------------------------------------------------
  相关解决方案