angle

Eliminating the jump to top of page behavior of the Ajax Toolkit Rating control

The Ajax Control Toolkit provides a number of Ajax-enabled server controls and extenders that make it very easy to add Ajax functionality to any ASP.NET driven site. One of these controls is the Rating control. One issue with the rating control is that when clicked, the user experiences a jump to top of page behavior. I have had a few emails from readers wondering how I eliminated this problem with the article rating feature at the bottom of each article page. This article examines how to eliminate this issue. 

Using Visual Studio, open the AjaxToolkit solution. Next from the Solution Explorer open the Rating.cs file and find the following line which should be about line 308, give or take.

writer.AddAttribute("href", "#");

Once you have found this line, change the "#" sign to "javascript:;". The line then looks this:

writer.AddAttribute("href", "javascript:;");

Recompile the Toolkit and then redeploy the updated dll to your site. We still have our null link but now when we click the star in the Rating control, the page will not jump to the top.