Rating Control with Multiples as User Control

Last post 01-03-2009 7:16 PM by Bobby-Z. 2 replies.

Sort Posts:

  • Rating Control with Multiples as User Control

    12-31-2008, 2:15 AM
    • Member
      671 point Member
    • Bobby-Z
    • Member since 10-04-2008, 1:53 AM
    • Orange County, CA
    • Posts 315

    I am using a web user control as a survey with multiple instances of the rating control; however, I have not been able to get it to work.

    I have 8 rating controls that go from 1 star to 10 stars.

    I also have an email textbox with a validator. The validator works when I hit the submit button, but the rating labels do not update 

    Protected Sub ImageButton1_Click1(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
    
         Dim rating1 As String = "[unknown]"
         Dim rating2 As String = "[unknown]"
         Dim rating3 As String = "[unknown]"
         Dim rating4 As String = "[unknown]"
         Dim rating5 As String = "[unknown]"
         Dim rating6 As String = "[unknown]"
         Dim rating7 As String = "[unknown]"
         Dim rating8 As String = "[unknown]"
    
    REDUNDANT CODE HERE !!!!!!!!!!!!!
    
         Select Case Layout.CurrentRating
          Case 1
              rating7 = "1"
         Case 2
              rating7 = "2"
         Case 3
              rating7 = "3"
         Case 4
              rating7 = "4"
         Case 5
              rating7 = "5"
         Case 6
              rating7 = "6"
         Case 7
              rating7 = "7"
         Case 8
              rating7 = "8"
         Case 9
              rating7 = "9"
         Case 10
              rating7 = "10"
         End Select
         Select Case Overall.CurrentRating
          Case 1
              rating8 = "1"
         Case 2
              rating8 = "2"
         Case 3
              rating8 = "3"
         Case 4
              rating8 = "4"
         Case 5
              rating8 = "5"
         Case 6
              rating8 = "6"
         Case 7
              rating8 = "7"
         Case 8
              rating8 = "8"
         Case 9
              rating8 = "9"
         Case 10
              rating8 = "10"
         End Select
    
            Label1.Text = rating1
            Label2.Text = rating2
            Label3.Text = rating3
            Label4.Text = rating4
            Label5.Text = rating5
            Label6.Text = rating6
            Label7.Text = rating7
            Label8.Text = rating8

     I am also going to average out the rating and store in a database ie there are a total of 80 points, so if 60 are chosen 60/8 = 7.5 stars

     I have been unable to get it to work properly yet!

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: Rating Control with Multiples as User Control

    01-01-2009, 10:32 PM
    Answer
    Hi Bobby-Z
     
    Based on my understanding, you need a Rating control include 10 stars, right?
     
    If so, the facing need can be achieve by one Rating control, please try the following demo:
      
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Rating1_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
        {
            int value = int.Parse(e.Value);
            string result = string.Empty;
            switch (value)
            {
                case 0:
                    result = "Not yet rated";
                    break;
                case 1:
                    result = "bad!";
                    break;
                case 2:
                    result = "Not very good";
                    break;
                case 3:
                    result = "average";
                    break;
                case 4:
                    result = "Good";
                    break;
                case 5:
                    result = "very good";
                    break;
    
            }
            lblRating.Text = result;
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <style type="text/css">
            .ratingStar
            {
                font-size: 0pt;
                width: 13px;
                height: 12px;
                margin: 0px;
                padding: 0px;
                cursor: pointer;
                display: block;
                background-repeat: no-repeat;
            }
            .filledRatingStar
            {
                background-image: url(FilledStar.png);
            }
            .emptyRatingStar
            {
                background-image: url(EmptyStar.png);
            }
            .savedRatingStar
            {
                background-image: url(SavedStar.png);
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
            </ajaxToolkit:ToolkitScriptManager>
            <ul>
                <li>rating:
                    <br />
                    <ajaxToolkit:Rating runat="server" ID="Rating1" MaxRating="5" CurrentRating="2" StarCssClass="ratingStar"
                        WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar"
                        Style="float: left;" AutoPostBack="true" OnChanged="Rating1_Changed">
                    </ajaxToolkit:Rating><br />
                    <asp:Label ID="lblRating" runat="server" Text="Selected value: " />
                    
                </li>
            </ul>
        </div>
        </form>
    </body>
    </html>
    
     

    If I’ve misunderstood the facing issue, please feel free to let me know.
     
    Thanks.

     

    Lance Zhang
  • Re: Rating Control with Multiples as User Control

    01-03-2009, 7:16 PM
    • Member
      671 point Member
    • Bobby-Z
    • Member since 10-04-2008, 1:53 AM
    • Orange County, CA
    • Posts 315

    I figured out the problem, but you had an idea i added so I marked yours as answer thanks

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
Page 1 of 1 (3 items)