Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have tried one code for rating using ajax
XML
<form id="form1" runat="server">
  <asp:ScriptManager ID="sm" runat="server" />
   <div>
   <div class="demoarea">
     <div class="demoheading">Rating Demonstration </div>
       <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <ContentTemplate>
             <div style="float: left; width:230;">How much do you like ASP.NET AJAX ?</div>
               <cc1:Rating ID="LikeRating" runat="server"
                   CurrentRating="3"
                   MaxRating="5"
                   StarCssClass="ratingStar"
                   WaitingStarCssClass="savedRatingStar"
                   FilledStarCssClass="filledRatingStar"
                   EmptyStarCssClass="emptyRatingStar"
                   OnChanged="LikeRating_Changed"
                   style="float: left;">
               </cc1:Rating>

               <br />
               <div style="clear:left;">
               <br />
                   <asp:Button ID="ButtonSubmit" runat="server" Text="Submit"
                       onclick="ButtonSubmit_Click" /><br /><br />
                   <asp:Label ID="LabelResponse" runat="server" Text="[ No response provioded yet.]"></asp:Label>
               </div>
           </ContentTemplate>
       </asp:UpdatePanel>
   </div>
   </div>
   </form>



in default.aspx.cs

C#
protected void LikeRating_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
    {
        e.CallbackResult = "Upate done. Value = " + e.Value + " Tag = " + e.Tag;
    }
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        string howMuch = "[unknown]";

        switch (LikeRating.CurrentRating)
        {
            case 1:
                howMuch = "a bit.";
                break;
            case 2:
                howMuch = "some.";
                break;
            case 3:
                howMuch = "a fair bit.";
                break;
            case 4:
                howMuch = "a lot.";
                break;
            case 5:
                howMuch = "more than any thing.";
                break;
        }

        LabelResponse.Text = "You like ASP.NET AJAX <b>" + howMuch + "</b>.";
    }


There is no error but i am not getting desired output

in output there are 5 stars....and by defult 3 stars are selected and when i am selecting 4th or 5th or any one star ...action is not performed ...
please provide your support
regards
Posted
Comments
SruthiR 5-Apr-12 6:49am    
Why do you set the CurrentRating in aspx as 3? Keep it as 0.
CurrentRating="0"

In the codebehind, get the rating from database and store to a variable. Then assign that value to your rating control.

LikeRating.CurrentRating = Convert.ToInt16(rating);

1 solution

Why do you set the CurrentRating in aspx as 3? Keep it as 0.

CurrentRating="0"

In the codebehind, get the rating from database and store to a variable. Then assign that value to your rating control.

LikeRating.CurrentRating = Convert.ToInt16(rating);
 
Share this answer
 
Comments
shivani 2013 9-Apr-12 7:35am    
I got your point to some extent about making CurrentRating="0" but when i run i want user to select the star of his choice and then star get selected but no action is performed so help me out on this
SruthiR 10-Apr-12 0:19am    
<pre lang="sql">Set UpdateMode and ChildrenAsTriggers properties of UpdatePanel. This is needed if u want postback from child controls of update panel. Try this.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="True">
<ContentTemplate>
<asp:Rating ID="Rating1" runat="server" CurrentRating="0"
StarCssClass= "ratingStar" FilledStarCssClass ="filledRatingStar"
EmptyStarCssClass = "emptyRatingStar" WaitingStarCssClass = "filledRatingStar" Visible ="true">
</asp:Rating>
</ContentTemplate>
</asp:UpdatePanel></pre>
shivani 2013 10-Apr-12 6:15am    
its not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900