This is my rating control in aspx page. When user click the star, i want to update the label3.
<style type="text/css">
.Star {
background-image: url(img/Star.gif);
height: 17px;
width: 17px;
}
.WaitingStar {
background-image: url(img/WaitingStar.gif);
height: 17px;
width: 17px;
}
.FilledStar {
background-image: url(img/FilledStar.gif);
height: 17px;
width: 17px;
}
</style>
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<ajaxToolkit:Rating ID="Rating1" AutoPostBack="true" OnChanged="OnRatingChanged" runat="server"
StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star" CurrentRating="2"
FilledStarCssClass="FilledStar">
</ajaxToolkit:Rating>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label runat="server" ID="label3"></asp:Label>
<asp:Label runat="server" ID="label4" Text="above"></asp:Label>
</div>
I tried out using Rating1.CurrentRating.ToString() but there is nothing on Label3.
protected void OnRatingChanged(object sender, RatingEventArgs e)
{
label3.Text = Rating1.CurrentRating.ToString();
}
Is my code wrong or I can get the value in another way? I'm planning to get the value from backend because later I will add it into my database. Please help. Thank you.
I think what are you looking for is
OnClick()
notOnChange()
, as when user click onRate
control and change it's rating value you want to get current value ofRate
control and show it in a label, BTW you should do following below desc,before doing anything think about the properties of
UpdatePanel
likeUpdateMode
andChildrenAsTriggers
that you can set them likeUpdateMode="Always" ChildrenAsTriggers="true"
forUpdatePanel1
if by setting them it still doesnt work do the below steps:1- Firstly move that label controls into the
ContentTemplate
ofUpdatePanel
2- Then handle
Click()
event ofajaxToolkit:Rating
3- At the end you must have something like in design mode:
and the code behind for
Rating1_Click
:this works like a charm!!!.