CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Check AJAX Rating control is Read-Only in JavaScript and Set AJAX Rating control to Read-Only in JavaScript
Submitted By Satheesh Babu B
On 3/17/2009 9:28:28 AM
Tags: AJAXControltoolkit,ASP.Net AJAX,CodeDigest  

Check AJAX Rating control is Read-Only in JavaScript and Set AJAX Rating control to Read-Only in JavaScript

 

Sometimes, we will have requirements to check if the AJAX control toolkit rating control is read-only or to set the AJAX Rating control to read-only in client side JavaScript.  For example, to customize the tooltip of Rating control using JavaScript before and after rating we need to check if the rating control is read-only to set the corresponding tooltip.

Read my previous article that discusses how to customize tooltip of rating control Customizing the Tooltip of Rating Control using jQuery

 

This little code snippet will help us to get and set read-only property of AJAX control toolkit's Rating control using JavaScript.

 

Get if Rating Control is Read-only in JavaScript

 

We can get if the rating control is read-only by calling a function called get_ReadOnly() of RatingBehaviour of Rating control. The Rating control is associated with a rating behaviour by default.  If you see the HTML source generated by the page that has a rating control, we can see this behaviour defined by the Rating control somewhere near the bottom. Something similar to,

 

Sys.Application.add_init(function() {

 

    $create(AjaxControlToolkit.RatingBehavior, {"AutoPostBack":true,"CallbackID":"RatingCtrl", "ClientStateFieldID":"RatingCtrl_RatingExtender_ClientState", "EmptyStarCssClass":"emptyRatingStar","FilledStarCssClass":"filledRatingStar"

,"Rating":4,"ReadOnly":true,"StarCssClass":"ratingStar",

"WaitingStarCssClass":"savedRatingStar", "id":"RatingCtrl_RatingExtender"}, null, null, $get("RatingCtrl"));

 

});

 

You can get the ID of the behaviour here.  If the ID of your Rating control is "RatingCtrl" then the id of the behaviour object will be Rating control ID concatenated by "_RatingExtender"( RatingCtrl_ RatingExtender, in our example.).  You can also set this property manually by setting BehaviourID property of the Rating control to have whatever name you like.

 

Get if it is Read-Only,

$find("RatingCtrl_RatingExtender").get_ReadOnly()

 

The above code will return true if it is readonly.

 

Set Read-Only,

$find("RatingCtrl_RatingExtender").set_ReadOnly(true);

 

The above JavaScript code can be put in client PageLoad event of ASP.Net AJAX page and make the AJAX Rating control to Read-Only or set it to Read-Only.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..