Please Donate: The Leukemia & Lymphoma Society - Scenic Shore 150 Bike Tour [Donate Here]

Fixing the Jumping AJAX Rating Control

February 22nd, 2008

If you are using the Rating Control for the ASP.NET AJAX Control Toolkit on a long page you will notice that after selecting your rating the page jumps to the top of the screen. On a short page you will not notice anything but the hash sign appearing at the end of the URL. On a long page the jump is a big problem. It is due to the href attribute on the anchor tags being set to a hash instead of something like javascript:void(0); which would prevent the jumping. I fixed this with one line of JavaScript using jQuery to set the link value to ensure clicking does not have the unwanted side-effect.

In the below sample I have the Rating Control wrapped in a div tag with Rating set as the CSS class. This way I can have many ratings on one page and having this one line fix all of them.

3 Responses to “Fixing the Jumping AJAX Rating Control”

  1. Naveed Mazhar Says:

    Hello,

    Nice topic.

    Can you please tell me where to put the following line?

    $('div.Rating a').attr('href', 'javascript:void(0);');

    Take care.

    Bye,

  2. Brennan Stehling Says:

    @Naveed,

    You need to run this line after the page has loaded. In jQuery you could use the "ready" function and with ASP.NET AJAX you could use Sys.Application.add_load(fn).

  3. Naveed Mazhar Says:

    Thanks for your reply. I am using ASP.Net 2.0. Can you please tell me where to put this "Sys.Application.add_load(fn)"?

    Can you please tell me in which function should I place this? And In .aspx form or in .aspx.vb file?

    Thanks.

    Take care.

    Bye,