Click here to Skip to main content
Licence CPOL
First Posted 13 Apr 2009
Views 36,109
Downloads 1,199
Bookmarked 66 times

ASP.NET Rating Control

By | 18 Apr 2011 | Article
An ASP.NET rating control

Introduction

There are many free rating controls on the internet, but I didn't find any control which fits these features:

  • Works well in UpdatePanel, GridView
  • Easy to customize UI and behavior
  • Auto generates JavaScript (does not need an external JS file)

So I decided to write an ASP.NET custom control as per my requirements.

Using the Code

How to use this control?

  1. Add a reference to the control,
  2. and:
    <%@ Page Language="C#" AutoEventWireup="true" 
    	Codebehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    
    <%@ Register Namespace="ASPnetRater" Assembly="ASPnetRater" TagPrefix="cc" %>
    <!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 runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <cc:Rater ID="Rater1" runat="server" 
    		ImageOff="/assets/images/rating_grey_star.gif"
                    Value="3" MaxValue="5" ImageOn="/assets/images/rating_red_star.gif"
                    ToolTip="I'm a rater" OnCommand="Rater1_Command" 
    		ImageOver="/assets/images/rating_yellow_star.gif"></cc:Rater>
            </div>
        </form>
    </body>
    </html>	 

This is the result:

Normal Status

Hover Status

Points of Interest

If you want the control to work well in an UpdatePanel, please make the control become a trigger of UpdatePanel:

ScriptManager1.RegisterAsyncPostBackControl(Rater1);

History

  • April 08, 2009: First draft
  • April 15, 2010: Updates
    • Fixed a bug while posting back, as reported by yuyejian
    • Uses the Enabled property to enable/disable the control
    • Image's URL supports URLs like "~/assets/..."
  • June 29, 2010: Updated source code
    • Fixed bug reported by maorray (Doesn't save/load the value of the rater to ControlState)
  • April 18, 2011: Updated source code
    • Added CommandName property
    • Calls base.RaiseBubbleEvent() in OnCommand()
    • This update will help the parent control such as GridView, DataList and the like to catch OnItemCommand event.

License

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

About the Author

taihip

Web Developer
SEA-Solutions
Vietnam Vietnam

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionExample needed on Rater Control Pinmemberpremalvala3:48 25 Jul '11  
AnswerRe: Example needed on Rater Control Pinmembertaihip4:15 25 Jul '11  
QuestionDataList [modified] Pinmemberzoran Jancic zozo1:46 18 Apr '11  
AnswerRe: DataList Pinmembertaihip15:34 18 Apr '11  
GeneralRe: DataList Pinmemberzoran Jancic zozo20:25 18 Apr '11  
GeneralMouse Over PinmemberMember 421013521:41 6 Dec '10  
GeneralRe: Mouse Over Pinmembertaihip21:56 6 Dec '10  
QuestionRe: Mouse Over PinmemberMember 421013522:15 6 Dec '10  
AnswerRe: Mouse Over Pinmembertaihip22:31 6 Dec '10  
GeneralRe: Mouse Over PinmemberMember 421013522:13 7 Dec '10  
Questionhow i get vote value in cs Pinmemberyuyejian21:41 13 Apr '10  
AnswerRe: how i get vote value in cs Pinmembertaihip5:36 14 Apr '10  
GeneralRe: how i get vote value in cs Pinmemberyuyejian18:56 14 Apr '10  
GeneralRe: how i get vote value in cs Pinmembertaihip2:58 15 Apr '10  
GeneralProblem with UpdatePanel PinmemberMember 39168742:03 2 Feb '10  
GeneralRe: Problem with UpdatePanel Pinmembertaihip5:11 2 Feb '10  
GeneralRe: Problem with UpdatePanel PinmemberMember 39168745:13 2 Feb '10  
GeneralRe: Problem with UpdatePanel Pinmembertaihip3:47 3 Feb '10  
GeneralRe: Problem with UpdatePanel Pinmembermaorray1:31 29 Jun '10  
GeneralRe: Problem with UpdatePanel Pinmembertaihip4:14 29 Jun '10  
GeneralRe: Problem with UpdatePanel Pinmembermaorray4:30 29 Jun '10  
GeneralRe: Problem with UpdatePanel Pinmembertaihip5:08 29 Jun '10  
GeneralResolveUrl Pinmemberernest_elias2:21 18 Jun '09  
AnswerRe: ResolveUrl [modified] Pinmembertaihip15:37 18 Jun '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120528.1 | Last Updated 18 Apr 2011
Article Copyright 2009 by taihip
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid