aspx不显示ViewState的实例
更新时间:2013年03月29日 11:00:07 作者:
重写Render方法,来去掉ViewState,提高网站的性能
复制代码 代码如下:
System.IO.StringWriter html = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(html);
base.Render(tw);
string Temp = html.ToString();
string s1 = string.Empty, s2 = string.Empty, s3 = string.Empty, s4 = string.Empty, s5 = string.Empty, s6 = string.Empty;
int i = 0;
int j = 0;
i = Temp.IndexOf("<form");
if (i > 0)
{
j = Temp.IndexOf(">", i);
s1 = Temp.Substring(0, i);
s2 = Temp.Substring(j + 1, Temp.Length - j - 1);
}
i = s2.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\"");
if (i > 0)
{
j = s2.IndexOf(">", i);
s3 = s2.Substring(0, i);
s4 = s2.Substring(j + 1, s2.Length - j - 1);
}
i = s4.IndexOf("<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\"");
if (i > 0)
{
j = s4.IndexOf(">", i);
s5 = s4.Substring(0, i);
s6 = s4.Substring(j + 1, s4.Length - j - 1);
Temp = s1 + s3 + s5 + s6;
}
else
{
Temp = s1 + s3 + s4;
}
Temp = Temp.Replace("</form>", "");
Temp = Temp.Replace("\r\n", "");
tw.Close();
Response.Write(Temp);
相关文章
ajaxControlToolkit中CascadingDropDown的用法说明
今天头叫写一个类似三级联动的控件,最好实现无刷新,是石油软件中的一个数据,需要表现出类似 X1-22 这样的格式,上下标的数据是固定的 想了很多办法来表现这个数字,最后决定用3个DropDownList控件2008-11-11
ASP .NET中执行控件(如ImageButton、LinkButton等)命令不刷新页面
在操作时,很多时候希望提交命令之后不刷新页面:1、防止页面拉动,2、防止主框架中刷新丢失当前运行的子界面。2009-03-03


最新评论