Using ASP.NET ViewState wisely

Let me clarify something first – if you think ViewState is there to repopulate your html forms, then you’re wrong. Many developers are under the impression that you should enable ViewState so that you do not have to re-assign values that a user has typed in a textbox, selected from a dropdown or checkbox. If you disable ViewState at page level by specifying EnableViewState=”false” in the page directive, you will still see the typed in value after a postback is made to the web form. Go check it for yourself! The values are restored to the controls because of the IPostBackDataHandler which they implement which basically sets their properties to the posted values.

So why do we need ViewState then?

ViewState can be helpful in situations where for example you don’t want to fetch data from your database and bypass binding altogether. This means that the first time a page is loaded, you query your database and then bind the data to a DataGrid for instance. On postback, ViewState will load the data back into the datagrid and you won’t have to do a round trip to the database server. There are also scenarios where ViewState can be a life saver but I won’t go into details about them now.

How to disable ViewState for all controls except a few ones?

If you want to disable ViewState at page level but want ViewState for a few selected controls, then you can use .NET 4 to achieve that. With earlier versions of the frameworks, you would have to loop through all the controls and enable/disable ViewState for those that you wanted because disabling it at page level would disable ViewState for every single control. However with framework 4, you can set ViewStateMode=”Disabled” on the page directive and set ViewStateMode=”Enabled” on the control that you wanted to have ViewState information. Note that you should not use EnableViewState=”false” but ViewStateMode=”Disabled” instead at the page level, otherwise no view state information will be saved.

Important things about ASP.NET ViewState

Even when you disable ViewState at the page level, you will still see the hidden viewstate field in your html because requires at least a bit of information on the control hierarchy of the page. Your page size will increase dramatically if you do not control the ViewState information. If you do not require ViewState, then turn if off (eg if you don’t need to do postbacks). Increase in page size because of view state means longer time to render the page and slower response time from server because it needs to save view state information as well. For fast loading pages, use view state on controls which need it.

You can also save view state information somewhere else rather than in the html being rendered. There’s a bit of serialisation to do and cleanup afterwards but it can be done.

For more information, please refer to

Favicon not showing up for website

I’m in the process of redesigning a website which was written in php and hosted on a linux box. I’m coding it in and as you’ve guessed it, will put it on a Windows server. I tried it with the following code:

<title>Testing favicon</title>
<link rel="Shortcut Icon" href="http://localhost/favicon.ico" type="image/x-icon" />

However the favicon does not show up and when I searched what was causing the problem, I found that windows treats favicon in a different way. So you have to change the favicon link to the following:

<link rel="Shortcut Icon" type="image/" href="http://localhost/favicon.ico" />

So for Microsoft Windows IIS, you will need to have the type as image/ rather than image/x-icon. I tested this on Internet Explorer 8 and the favicon.ico appeared but that did not work for Firefox 3.5.11. I had to try a couple of things to get it to work. So here are the solutions if you’re having problems with your favicon:

  • Make sure the favicon.ico is 16px X 16px and that you have not just renamed a gif or jpg or png file to .ico
  • Delete your browsers cache and reload the page (you can delete the whole internet history if you like
  • Try to bookmark the page where you have the favicon and see if that works. Delete and bookmark again if it doesn’t work first time round.
  • Close Firefox or any browser you’re using and launch it again

What worked for me was to close Firefox and when I restarted it, the favicon displayed without any problems. This is something to do with the cache – when you open a new firefox session, firefox pulls over the new details, otherwise you’ve got stale data that it uses until you close the program.

Reasons why MySQL table crashed and how to repair it

A few days ago, I was trying to update a record in my database and encountered an error message in the form of “Incorrect key file for table xxx.MYI”. Since the update was not really that important, I decided to ignore that warning but this was a very big mistake that I would regret later. I went out for the day and when I came back at night, I found that my traffic has plummetted and when I investigated, I found that the table that was having problems earlier has crashed. So I decided to find reasons why MySql tables would crash and they are as follows:

  • Unstable operating system
  • Problems with the hardware
  • Power failure
  • Corrupted data or index files
  • MySql server host was killed during an update
  • External program manipulating the data or index files at the same time as MySqlId without locking the table properly

There may be other causes for MySql to crash but the reasons above are more common.

How to repair a crashed MySql table?

Fortunately MySql tables which have been crashed can be repaired quite easily. All you have to do is use PhpMyAdmin or another MySql client program and run the repair command on that table (REPAIR TABLE employee). This will bring back the table in a consistent state. You can also use CHECK TABLE employee to see if there are any problems with the tables in your database. There are additional options that you can use when repairing/checking your tables but using the syntax without them should work just fine.

How detrimental can it be to have crashed MySql tables?

The MySql table in my database crashed around 15:00 and it was not until 22:00 that I noticed the problem. That’s the problem when you’re on shared hosting – you don’t get any notifications of problems and when you email support, it takes time for them to get the problem fixed. My website is database driven which means that if the database is down, the whole website is brought down. Running the repair command took less than a minute though and everything was back up after the table was repaired.

However I lost half of my daily traffic within that time and lost half of my revenue as well. Of course, having a website that’s not working is not good for your visitors and losing money is not something that you want but those are not the biggest problems. For the duration of the downtime, search engine spiders (GoogleBot) may be crawling your website and when they encounter problems with the site, they can quickly remove your webpages out of their index and that will cost you even more than 1 day of downtime. Your rankings might suffer as well as a result of the downtime.

Using Facebook to get more traffic to your website

Everyone these days seem to have a facebook account. Why shouldn’t they? Facebook has become a central point of communication in our daily life and helps us stay in touch with friends and family and see what they are doing without much effort. Holiday pictures, video albums and latest gossip are at out fingertips and as more people join the network, it becomes even more important for us webmasters to leverage the power of Facebook.

Use Facebook Connect to give visitors an alternative to registering on your website

Let’s face it – nobody likes having to register on websites to access a service, whether it’s for commenting on an article or asking a question on a forum. With so many websites out there, it becomes very difficult to keep track of the different username/password for each site and this is a major put off for a lot of visitors. By allowing the visitors of your site to login using Facebook, you’ll get more people to post on your site or better still engage more. You will get access to the visitor name, email address, friends and a lot more. All the essential details that you want to capture in your registration page will be made available to you with Facebook Connect. Of course this should be used to complement your own registration page because not everyone is on Facebook and you cannot just allow anyone to engage with your site without registration because that’s going to get the attention of spammers but using Facebook Connect will make users engage more with your site.

Let other people know about your content with Facebook Share button

Facebook Share button is a bit different from Facebook Like button and is meant to be used to allow sharing your content even easier. If you display a Facebook Share button on your site and a user clicks it, your content will be made available to all the friends of this user. This is viral marketing in its simplest. The average Facebook user has around 120 friends and that content will be read by that many people if not more. A count of the number of times the content has been shared is shown next to the button as well and this shows how popular was content is.

Facebook Like button is a great way to get more people to visit your website

When people click on the Facebook Like button on your website, it tells you how many people actually like your content and since this is syndicated to the user’s activity in Facebook, you will get other people to your site who want to check what it is all about.  Some people like using the Like and Share button alongside and it’s not that difficult to set up even for beginners.

Facebook API

If you have a website, you’ll need to get a Facebook API key to get the most of what Facebook has to offer you. You can use the Standard JavaScript SDK to enable Facebook features on your site but you’ll need access to that API key. Of course, if you’re a more experienced programmer, you can always code your own things and get more advanced features by querying Facebook.

What, PR6 sites selling links?

I was contacted by someone on a popular webmaster forum to buy a link on a site which has a valid PR6. The government site belongs to a council and because government sites tend to link to each other a lot, it has a lot of good quality inbound links. Getting links on such a site can really boost your ranking especially if you use a good targetted anchor text. However they are very hard to come by. Unless you’re a non-profit organisation or offering something unique which would be beneficial for the site and at the same time be relevant, you’re not going to get a link from them.

Part of me wanted to buy the link because I know that it will increase the PR of my site and boost my rankings as well. The price was $150 for 3 months, $250 for 6 months and $400 for 12 months. The link would be placed on the homepage and you get to choose your anchor text. I was curious and wanted to see if other people have purchased links on that PR6 site. All paid links were placed like halfway down the homepage as follows:


As you can see from the above example, all these links look like spam even if it comes from a reputable website such as this one. Placing your website’s link there could do you more harm than good. It is not worth paying $400 a year to get such a link. If you’re already receiving traffic from Google, why would you want to risk your organic traffic and be penalised?

I didn’t include the URL for this site deliberately but the only reason you can buy links on there is because they’ve got an immoral person working for them. Councils are not stupid to publicly do this sort of thing but a staff who has got access to the website (probably an IT guy who maintains the website content) decided to do a little business on the side. I’m pretty sure the council is not aware of this and the moment they find out, they will fire him.

The conclusion is that buying links can jeopardise your website a lot. You’re better off using whitehat techniques and moving up the SERPs slowly but surely than regretting the big mistake of thinking you’re purchasing once in a lifetime link deal to boost your rankings.

How to tackle Google Maydate Update?

Sometime around 28 April 2010 t0 3rd May 2010, many webmasters noticed an unusual change in the SERPs. This has been named the Google Mayday Update. The ranking algorithm was changed to make search more relevant as always. But what was this update all about? This change is most noticeable for long tail keywords rankings. Many large sites have seen a drop in traffic because they were no longer ranking for the long tail keywords (or have been dropped several places in the SERPs) and this has consequently plumetted their traffic.

Before the Google Maydate Update, a website was able to rank for long tail keywords based on domain authority. So if you had a website about finance with a high PR homepage, domain trust and good rankings for your primary keywords, then you would be able to get long tail traffic easily (eg rank for best car insurance for young drivers) if one of your finance articles mentioned a few of the long tail keywords being searched for. This was true even if your article was placed quite far from the homepage (many clicks to get to it) and also if there were few or none links pointing to it.

Solution for the Mayday update

Many ecommerce websites use generic description of products from manufacturers and as you can guess, this give rise to duplication. Now the problem is that as a customer who wants to by a particular product, you don’t want to click on each of the results on google when you have done a search and end up seeing the same description and everything for a product. You want to see something unique, something that’s going to help you in your decision making process. This is why google has started to filter out similar pages with the Mayday Update. This is supposed to help with user experience and bring more relevance to searches.

Your first step if you have been hit by the Mayday Update is to look at the pages on your site and analyse them. If you have the same content that’s practically on everyone else’s site, then you have a problem. You need unique and original content for your site but that might be hard if you have thousands of pages. User generated content is a way to add uniqueness to your product pages. You can give users the facility to review the products on your website. Don’t just show the good reviews and filter out the bad ones though! There needs to be a balance of reviews, both good and bad, otherwise people are going to find it unnatural and you’ll eventually lose potential customers (more on that some other time).

The other thing you should do is create more links to the inner pages of your site. Many people like getting links to their homepage. That’s good if you want your homepage to rank but if your other pages are buried deep down in your site, like requiring 5 clicks to get to it, well then chances are google will not index it but if it does, it may not rank it well. The closer to the homepage the better but if you can’t do that, then you need external links to point to these deep pages. This will show to Google that your page contains worthy content.


What many people fail to realise is that you do not need to stay ahead of Google to ensure long term ranking. Google’s aim is to provide the most relevant and accurate results for a given search query. If you align Google’s aim with your website, you’ve already secured your website’s future. So instead of changing your website everytime Google makes an algorithm change, you just need to focus on creating a better user experience for your visitors and delivering better content/services to help them out.