Forum Moderators: open
It seats within the <head> tags, is fairly big and looks ugly.
Is there a way to get rid of it or move it to an external folder?
Thanks.
To disable viewstate put the following line at the top of your aspx pages.
<%@ Page EnableViewState="false" %>
Bear in mind that the viewstate is necessary in ASP.Net to maintain state for controls between pages, so if you're features that require state management, they will no longer work properly.
One common misconception is that you *need* a server <form> tag for each .aspx page. This is largely due to Visual Studio plopping one in each page when you add an .aspx page to a project. Not all asp.net controls require the form.. so if your page doesn't need a server <form>, don't use it. When you omit the server <form> ViewState is not recorded and your pages are much lighter weight.
Don't get me wrong, ViewState is really nice and convenient! Just be aware of the need to mimimize it's size, and you will be in good shape.
' This method overrides the Render() method for the page and moves the ViewState
' from its default location at the top of the page to the bottom of the page. This
' results in better search engine spidering.
'
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter)
MyBase.Render(htmlWriter)
Dim html As String = stringWriter.ToString()
Dim StartPoint As Integer = html.IndexOf("<input type=""hidden"" name=""__VIEWSTATE""")
If StartPoint >= 0 Then 'does __VIEWSTATE exist?
Dim EndPoint As Integer = html.IndexOf("/>", StartPoint) + 2
Dim ViewStateInput As String = html.Substring(StartPoint, EndPoint - StartPoint)
html = html.Remove(StartPoint, EndPoint - StartPoint)
Dim FormEndStart As Integer = html.IndexOf("</form>") - 1
If FormEndStart >= 0 Then
html = html.Insert(FormEndStart, ViewStateInput)
End If
End If
writer.Write(html)
End Sub