Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Write View State at bottom of the Page for SEO Friendly Site

Posted by Viral Sarvaiya on November 24, 2009

first of all create class file named ‘basepage.vb’ and add this code to class file

then after inherit this class file from page

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim stringWriter As New System.IO.StringWriter
Dim htmlWriter As 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
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
StartPoint = html.IndexOf(“<input type=”"hidden”" name=”"__EVENTTARGET”"”)
If StartPoint >= 0 Then
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
StartPoint = html.IndexOf(“<input type=”"hidden”" name=”"__EVENTARGUMENT”"”)
If StartPoint >= 0 Then
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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: