I have a rating control that shows the average rating of a user supplied posting (think of a forum post that others will rate). So if the average rating for that posting is lets say 3 out of 5 all users will see 3 stars. If someone wants to rate the posting,
then they could click lets say 4 stars and I save the rating to the database, re-average the current rating and display the result (which may or may not still be 3 at this point). So far so good. The problem comes in when a user wants to agree that it's 3
stars. Since the rating control currently shows 3 stars, choosing 3 again does not cause a postback. In my case even though the value didnt technically change, I need to capture the users choice so I can average it in and save that users rating. I also modify
the UI so that I can show each user of the site what he/she choose as a rating.
How can i get the control to let me know that a user choose a star rating even if its the same one the control is currently displaying?
Thats not a bad idea. I will look into it. In the mean time I d/l the source code for the ajax toolkit and solved the problem by opening up the RatingBehavior.pre.js file and in the set_Rating : function(value) {...} method, I commented out 'if (this._ratingValue
!= value) {' and its ending '}' .
So now the setter always fires the callback. It works just fine, but there is no user feedback to let the user know that the new rating was accepted. Also, I may not want that behavior in other places in the application. I am gonna look into what you found
and see if it will fit my needs.
Either way, I think I have solved it. I am gonna mark your post as an answer because even if I dont use it, I think it will work for others!!
Savij
Member
5 Points
6 Posts
Rating Control Average Rating and Postback on same rating
Feb 20, 2011 09:01 PM|LINK
Hello,
I have a rating control that shows the average rating of a user supplied posting (think of a forum post that others will rate). So if the average rating for that posting is lets say 3 out of 5 all users will see 3 stars. If someone wants to rate the posting, then they could click lets say 4 stars and I save the rating to the database, re-average the current rating and display the result (which may or may not still be 3 at this point). So far so good. The problem comes in when a user wants to agree that it's 3 stars. Since the rating control currently shows 3 stars, choosing 3 again does not cause a postback. In my case even though the value didnt technically change, I need to capture the users choice so I can average it in and save that users rating. I also modify the UI so that I can show each user of the site what he/she choose as a rating.
How can i get the control to let me know that a user choose a star rating even if its the same one the control is currently displaying?
Thanks for any help!!
-Jeff
rivdiv
All-Star
16323 Points
2595 Posts
Re: Rating Control Average Rating and Postback on same rating
Feb 21, 2011 02:42 AM|LINK
You could have a HoverMenuExtender with a second Rating control to rate.
See this post: http://forums.asp.net/p/1525984/3683345.aspx
Savij
Member
5 Points
6 Posts
Re: Rating Control Average Rating and Postback on same rating
Feb 21, 2011 03:31 AM|LINK
rivdiv,
Thats not a bad idea. I will look into it. In the mean time I d/l the source code for the ajax toolkit and solved the problem by opening up the RatingBehavior.pre.js file and in the set_Rating : function(value) {...} method, I commented out 'if (this._ratingValue != value) {' and its ending '}' .
So now the setter always fires the callback. It works just fine, but there is no user feedback to let the user know that the new rating was accepted. Also, I may not want that behavior in other places in the application. I am gonna look into what you found and see if it will fit my needs.
Either way, I think I have solved it. I am gonna mark your post as an answer because even if I dont use it, I think it will work for others!!
Thanks for the help!
-Jeff
vjswaroop
Member
12 Points
10 Posts
Re: Rating Control Average Rating and Postback on same rating
Mar 17, 2011 07:01 AM|LINK
Hi Savji,
Did u get the solution for Displaying the average value in Ajax rating Control?
If so please help me in solving that.
Swaroop Vuppala
dsuper
Member
6 Points
3 Posts
Re: Rating Control Average Rating and Postback on same rating
Apr 21, 2012 03:02 PM|LINK
Hello
I've encapsulate the rating control with <div onclick="sameRatingClicked();">
and added the client side function:
function sameRatingClicked(){
var currentRating = document.getElementById('rating_RatingExtender_ClientState');
if (currentRating != null && currentRating.value == <% =m_ratingValue%>)
{ __doPostBack('rating','');} }
m_ratingValue is the server side value of the initial rating, 'rating' is the rating control id.
The post back will reach the OnChanged event handling.
Danny