Moving ViewState and Other Hidden Variables to the Bottom of the Page - Update
Earlier I wrote about a method of moving the ViewState to the bottom of the page. The advantages of this are two fold, one is it helps with search engine optimization by getting non-essential content out of the top of the page. Second since it is at the bottom of the page it helps the important content to render just a little bit faster.
I have an update to my render method that uses regular expressions to extract the hidden variables and move them to the bottom of the page.
AsMatchCollection = Regex.Matches(html,
sViewState = m.Value
html = html.Replace(sViewState,
sEventTarget = m.Value
html = html.Replace(sEventTarget,
sEventAurgument = m.Value
html = html.Replace(sEventAurgument,
html = html.Replace(
& sViewState & sEventTarget & sEventAurgument &
I extracted the method out of the event handler, just so I could do a little better long term code maintenance. I am moving three hidden input variables to the bottom of the page, but will probably just change this to move every hidden input beofre too long.
A little explanation about what is going on. If you are not familiar with Regular Expressions, I can not encourage the learning of the Regex object enough, it is magical. I will not cover the actual expression, but note that the RegEx.Matches method returns a MatchCollection containing all the strings that match the given regular pattern.
I then iterate through the returned MatchCollection to get each match. If the Value, or matched string, contains the id I am looking for, then I set the value to a string I defined to hold the tag. Then I replace the string of text with an empty string to get it out of the HTML. When I am done looping through the list of matches I then strip the Form close tag (</Form>) from the HTML and place my hidden variables, then append the form close tag back.
This example targets three specific hidden inputs, but I think I will finally settle on a solution that grabs all hidden input tags and moves them to the bottom of the form. I am just taking steps as I can. I actually will be discussing ViewState Optimization techniques in the coming days, so stay tuned.