Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/chridpkm/chrisrios.com/wp-includes/functions.php on line 6114
web method Archives - Christian Rios' Blog

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.