网站开发文本模版,php网站路径问题,珍爱网建设网站的目的,卫辉网站建设在进行 ASP.NET 开发时#xff0c;有时候需要对页面输出的最终 HTML 源代码进行控制#xff0c;是页面的 render 方法中很容易实现这个功能。下面就是一个实现的方法#xff0c;注释都在代码中。 [c-sharp] view plaincopy % Page LanguageC# % % …在进行 ASP.NET 开发时有时候需要对页面输出的最终 HTML 源代码进行控制是页面的 render 方法中很容易实现这个功能。下面就是一个实现的方法注释都在代码中。 [c-sharp] view plaincopy % Page LanguageC# % % Import NamespaceSystem.IO % !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd script runatserver protected override void Render(HtmlTextWriter writer) { string content string.Empty; StringWriter stringWriter new StringWriter(); HtmlTextWriter htmlWriter new HtmlTextWriter(stringWriter); try { // 将当前页面的内容呈现到临时的 HtmlTextWriter 对象中 base.Render(htmlWriter); htmlWriter.Close(); // 得到当前页面的全部内容 content stringWriter.ToString(); // 替换页面中的部分内容 string newContent content.Replace([mxh], 孟宪会); // 将新页面的内容显示出来 writer.Write(newContent); } catch { } finally { stringWriter.Dispose(); htmlWriter.Close(); htmlWriter.Dispose(); } } /script html xmlnshttp://www.w3.org/1999/xhtml head idHead1 runatserver title孟宪会之替换页面呈现内容测试/title /head body form idform1 runatserver [mxh] /form /body /html 转载于:https://www.cnblogs.com/feb9903/p/3514852.html