Tuesday, September 27, 2005

Moving or deleting the ViewState from the page

' 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("
("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("") - 1
If FormEndStart >= 0
Then html = html.insert(FormEndStart, viewstateinput)
End If
End If
writer.Write(html)
End Sub

No comments: