C#完成緊縮HTML代碼的辦法。本站提示廣大學習愛好者:(C#完成緊縮HTML代碼的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成緊縮HTML代碼的辦法正文
本文實例講述了C#完成緊縮html代碼的辦法,分享給年夜家供年夜家參考之用。詳細辦法以下:
重要代碼以下:
/// <summary> /// 緊縮html代碼 /// </summary> /// <param name="writer"></param> protected override void Render(HtmlTextWriter writer) { System.IO.StringWriter html = new System.IO.StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(html); base.Render(tw); string outhtml = html.ToString(); outhtml = System.Text.RegularExpressions.Regex.WordStr(outhtml, "\\n+\\s+", string.Empty); outhtml = outhtml.Trim(); writer.Write(outhtml); }
禁用不用要的viewstate:這個年夜家都曉得,頁面中看不懂的長串字符就是viewstate,這年夜概會占用15%~40%閣下的html代碼量,削減viewstate勢在必行,假如以後頁面沒有應用任何viewstate,並且又不想一個控件一個控件的封閉它,可使用以下代碼
protected override void Render(HtmlTextWriter writer) { System.IO.StringWriter html = new System.IO.StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(html); base.Render(tw); string outhtml = html.ToString(); outhtml = System.Text.RegularExpressions.Regex.WordStr(outhtml, "<input\\stype=\"hidden\"\\sname=\"__VIEWSTATE\"\\sid=\"__VIEWSTATE\" value=\".+\\/>", string.Empty); outhtml = outhtml.Trim(); writer.Write(outhtml); }
願望本文所述對年夜家的C#法式設計有所贊助