asp.net viewstate and seo
Posted on March 18th, 2009 • Filed under asp.net • No Comments
asp.net viewstate is a wonderful invention, but can bloat your html. For most users this is probably going to have minimal impact on the page load time. But for search engines spiders you really want to minimise needless information, especially near the top of the page.
It’s best practice to turn off viewstate for the whole page or for individual usercontrols if they don’t require viewstate. The deciding factor here is: does the page or usercontrol perform postbacks.
Even with careful pruning of viewstate you’ll probably find your viewstate is still large…
What you can do
Now there are a couple of strategies I’ve seen for working round this, both involve overriding the page
1 is to intercept the page rendering and move the viewstate hidden variable to the bottom of the page.
Here’s an example http://www.dotnetdiary.com/labels/Moving%20ViewState%20Field.html
2 is a very clever solution that keeps the viewstate information on the server and justs passes a key back and forth to the client.
I read about this approach here http://www.eggheadcafe.com/articles/20040613.asp
Here’s my approach
Now since I don’t think that viewstate bloat has too much of an impact on page performance for real users I’m only going to worry about search engine spiders.
asp.net has a way of detecting spiders – now I’m not saying it’s going to be 100% accurate but in my tests it’s been accurate enough for this technique.
In the page load of your page (or master page)
If Request.Browser.Crawler Then Page.EnableViewState = False
er that’s it, pretty simply eh?
You can verify if this is working by viewing the source of the cached version of the page that google holds.
Hope that helps!
ASP.NET Event Validation and “Invalid Callback Or Postback Argument”
Posted on February 5th, 2009 • Filed under asp.net, Javascript • No Comments
I was getting this and pulling my hair out. My button (server-side) was pumping out a bit of javascript And this kept causing the error. I tried using the prescribed fix: ClientScript.RegisterForEventValidation(mycontrol.uniqueid) in the prerender. Still got the error. Here’s how I fixed it. RegisterStartupScript does the job of running at startup by emiting the js right [...]
Use jQuery to replace <body onunload="GUnload()">
Posted on January 26th, 2009 • Filed under Javascript • 12 Comments
When using Google maps it’s important to use GUnload on the page’s unload event. Fine when you can access the body tag directly…. But if you have the Google map functionality wrapped inside an ascx you need a different approach. After a big of digging I found how to use jQuery to “catch” the unload [...]
Need to access session variables in an ashx?
Posted on January 16th, 2009 • Filed under asp.net • 4 Comments
Just a quick note if you need to access session variables from an ashx, you need to implement SessionState.IRequiresSessionState or IReadOnlySessionState if you only need to read the vars In your ashx change to
My first iPhone app
Posted on October 25th, 2008 • Filed under iPhone • No Comments
Despite not owning an iPhone (I want one!), I’ve built my first iPhone application. It’s a web app for playing Suduko. It generates a new grid every day. Utilises jQuery of course. Find it here http://sudoku.nerdboy.co.uk/ I used http://www.testiphone.com/ to see that it worked and fitted the screen. If anyone reading this actually has an iPhone and the [...]
Firebug for Google Chrome Campaign
Posted on October 25th, 2008 • Filed under Browsers • 8 Comments
I’ve been a Firefox fan for ages and when I discovered Firebug my life became a whole lot easier. So much so, that I’d hate to be without it. But… I’m loving Google Chrome for it’s sheer speed. I never realised Firefox was slow until I tried Chrome – maybe it’s all the extensions I [...]
Required field validator for an fckeditor
Posted on October 7th, 2008 • Filed under asp.net • 2 Comments
Unfortunately a requiredfieldvalidator doesn’t work with the fckeditor. The way to do this is to use a custom validator. Important note: you need to set validateemptytext=”true” otherwise it doesn’t fire Then add the following javascript (note that I’m using jQuery here to reference the validator control) You might also want to handle the server-side validation [...]
Find a control within a area
Posted on October 7th, 2008 • Filed under asp.net • No Comments
If you are using master pages, you may expect that you can find a control within an tag with the following me.findcontrol(“fckEditor”) But unfortunately that doesn’t work. You need to make a reference to the place holder the control is in, then find the control within the place holder. Another gotcha here is that you [...]
Lo-Fi unzipping functionality for .net
Posted on October 2nd, 2008 • Filed under asp.net • No Comments
I’ve looked for unzipping functionality for .net a couple of times over the years and never found a totally satifactory solution. In a recent project I had to grab an attachment from a POP box and then unzip the attachment. I found an unzipping product called 7zip, it’s open source and there’s a command line [...]
asp.net outputcache based on url
Posted on October 1st, 2008 • Filed under asp.net • No Comments
The outputcache page directive is very handy – and I tend to use this where appropriate on my usercontrols (.ascx) You can optionally vary by querystring parameters. Something that’s missing from the default options is to vary based on the actual url of the page. I was building a site where a random testimonial was [...]