jQuery Star Rating Plugin Web Method Call with ASP.Net

I started playing with the jQuery Star Rating Plugin v3.14. But, I could not really find a good way to make web method calls or a decent write up of how to use it with ASP.Net.

So, I added auto-submit-star to the markup for it to make the callback, added runat=”server”, and a hidden field with the record id.

<input name="star1" type="radio" class="auto-submit-star" runat="server">
<input name="star1" type="radio" class="auto-submit-star" runat="server">
<input name="star1" type="radio" class="auto-submit-star" runat="server">
<input name="star1" type="radio" class="auto-submit-star" runat="server">
<input name="star1" type="radio" class="auto-submit-star" runat="server">
<asp:HiddenValue id="hfRatingID" runat="server"/> 

After that, added the following script that performs the jQuery Web Method call

$(".auto-submit-star").rating({ callback: function (a, b) { 
PageMethods.RateIt( $(this).siblings('input[id*="hfRatingID"]').val(), a) 
}})

Then makes web method call to a static class in code behind

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static void RateIt(int id, string value) // Method have to be static { 
// Make call to update DB rating value 
}

Now you should be able to make an asynchronous call for users to rate an item. Hope this helps.

Limit the number of items the user can select in a ListBox with JQuery

This little script is able to grab all the listboxes on the page.

      $(document).ready(function() {
          $("select").change(function() {
             if ($(this).find('option:selected').length > 5) {
               this.options[this.selectedIndex].selected = false;
             }; }); }); 

pretty sleek huh?