customizing rating control

Last post 07-12-2009 11:55 PM by integrasol. 3 replies.

Sort Posts:

  • customizing rating control

    07-11-2009, 11:12 PM

    Hi,

    The rating example (shown in http://www.asp.net/learn/ajax-videos/video-374.aspx ) displays a message “you like this site a lot” when you click on submit button.

    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 this site <b>" + howMuch + "</b>.";

        }

    Instead I want this message to be displayed when I select the stars in the rating control i.e. when I select 4 stars it should display “you like this site a lot”(no button control). Is there any method which will allow me to do this? Can anyone help me with this?

    Thank you.

  • Re: customizing rating control

    07-12-2009, 6:14 AM
    • Star
      8,892 point Star
    • integrasol
    • Member since 06-05-2009, 11:18 AM
    • Denmark & Spain
    • Posts 1,657

    Yes, you need to add code in the OnChanged event, which I believe has already been done in the example code that comes with video.

    Then, check out this post that describes how to catch the CallbackResult client-side, http://flavio-kb.blogspot.com/2008/03/ajax-control-toolkit-rating-control.html.

    Thanks

    Carsten

    Please click Mark as Answer if this post is of help to you. :-)



    My Blog
  • Re: customizing rating control

    07-12-2009, 7:31 PM

    Thanks for your reply, Integrasol . Correct me if I am wrong, the above link is about displaying a message to user, not allowing the user to rate again (only one attempt for each user for rating) and saving results to a database file!!

    I tried the link but it is giving me some errors. I don’t know whether I am following the steps correctly or not. This is what my html (.aspx) looks before changes.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

     

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title>rating Control Demo</title>

        <link href="StyleSheet.css" rel="stylesheet" type="text/css" />

    </head>

    <body>

        <form id="form1" runat="server">

            <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />

           <div>

        <div>

          <div>Rating Demonstration </div>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">

                <ContentTemplate>

                  <div style="float: left; width:170;">Rate My Site?</div>

                    <cc1:Rating ID="LikeRating" runat="server"

                       CurrentRating="0"

                        MaxRating="5"

                        StarCssClass="ratingStar"

                        WaitingStarCssClass="savedRatingStar"                      FilledStarCssClass="filledRatingStar"

                        EmptyStarCssClass="emptyRatingStar"

                        OnChanged="LikeRating_Changed"    

                        style="float: left;">

                    </cc1:Rating>

                    <b />

                    <div style="clear:left;">

                    <br />

                      </ContentTemplate>    

            </asp:UpdatePanel>

    </div>

        </div>

        </form>

    </body>

    </html>

    This is how it looks like after changes(showing only the body)

    <body>

        <form id="form1" runat="server">

            <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />

           <div>

        <div>

          <div>Rating Demonstration </div>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">

                <ContentTemplate>

                  <div style="float: left; width:170;">Rate My Site?</div>

                    <cc1:Rating ID="LikeRating" runat="server"

                       CurrentRating="0"

                        MaxRating="5"

                        StarCssClass="ratingStar"

                        WaitingStarCssClass="savedRatingStar" BehaviorID="RatingBehavior1"

                        FilledStarCssClass="filledRatingStar"

                        EmptyStarCssClass="emptyRatingStar"

                        OnChanged="LikeRating_Changed"    

                        style="float: left;">

                    </cc1:Rating>

                   

    <script type="text/javascript">

                    Sys.Application.add_load(function() {

    $find("RatingBehavior1").add_EndClientCallback( function(sender, e) {var responseTag = $get('lblResponse'); responseTag.innerHTML = e.get_Callback

                    </script>

                   

    <span id="lblResponse"></span>

                    <b />

                    <div style="clear:left;">

                    <br />

                       

                        <asp:Label ID="LabelResponse" runat="server" Text="[ No response provioded yet.]"></asp:Label>  

                    </div>

                </ContentTemplate>    

            </asp:UpdatePanel>  

           

        </div>

        </div>

        </form>

    </body>

    Coming to the aspx.cs file i.e. the callbackresult at client side…I am not able to understand the code. It seems like its converting the message which is of integer type to string and displaying it! So, just used a string to display the message

    protected void LikeRating_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)

        {

            Thread.Sleep(500);

            string message = "thanks";

            e.CallbackResult = message;

        }

    But nothing works. What am I doing wrong?

    Thanks for your help.

  • Re: customizing rating control

    07-12-2009, 11:55 PM
    Answer
    • Star
      8,892 point Star
    • integrasol
    • Member since 06-05-2009, 11:18 AM
    • Denmark & Spain
    • Posts 1,657

    Actually, the link will simply update the text of an HTML element, each time the Rating control is clicked. I've added a Web Form that works.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>rating Control Demo</title>
        <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="sm" runat="server" />
    
        <script type="text/javascript">
            Sys.Application.add_load(function() {
                $find("RatingBehavior1").add_EndClientCallback(
                function(sender, e) {
                    var responseTag = $get('LabelResponse');
                    responseTag.innerHTML = e.get_CallbackResult();
                });
            });
        </script>
    
        <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;" BehaviorID="RatingBehavior1">
                        </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>
    </body>
    </html>
    


     

     

    Thanks

    Carsten

    Please click Mark as Answer if this post is of help to you. :-)



    My Blog
Page 1 of 1 (4 items)