using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
protected void Rating2_Changed2(object sender, AjaxControlToolkit.RatingEventArgs e)
{
int value = int.Parse(e.Value);
string result = string.Empty;
switch (value)
{
case 0:
SqlDataSource1.Insert();
break;
case 1:
SqlDataSource1.Insert();
break;
case 2:
SqlDataSource1.Insert();
break;
case 3:
SqlDataSource1.Insert();
break;
case 4:
SqlDataSource1.Insert();
break;
case 5:
SqlDataSource1.Insert();
break;
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
Actually, above is a part of RatingBehavior.js. To get the your goal, you shall modify the source code and recompile it. Now you can use it in your project.
Best regards,
Jonathan
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
-Oleksandr-
Member
2 Points
17 Posts
Onclick() method in ajaxtoolkit control "Rating"
Apr 11, 2008 07:15 AM|LINK
Hi, I'm using framework 3.5, mssql 2005 and ajaxtoolkit control "Rating".
There is no Onclick() method =(, only onchenged().
If currentrating 3 and user click 3 it doesn't work, when I'm trying to bind data in to database.
Is the any solver for this problem?
Please help.
This is my code:
.aspx:
<html >
<head id="Head1" runat="server">
<title>ASP.NET Example</title>
<style>
/* The following styles are for the Rating */
.ratingStar {
font-size: 0pt;
width: 13px;
height: 12px;
margin: 0px;
padding: 0px;
cursor: pointer;
display: block;
background-repeat: no-repeat;
}
.filledRatingStar {
background-image: url(Images/FilledStar.png);
}
.emptyRatingStar {
background-image: url(Images/EmptyStar.png);
}
.savedRatingStar {
background-image: url(Images/SavedStar.png);
}
/******************************************/
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="1">
<ProgressTemplate>
Loading...........
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
<asp:Panel ID="Panel1" runat="server">
<cc1:Rating ID="Rating1" runat="server"
CurrentRating='2'
EmptyStarCssClass="emptyRatingStar" FilledStarCssClass="filledRatingStar"
StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar"
CommandName="Insert" AutoPostBack="true" OnChanged="Rating2_Changed2" >
</cc1:Rating>
</asp:Panel>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("CustomerRating") %>'></asp:Label>
</ItemTemplate>
</asp:FormView>
<br />
<br />
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:ConnectionString %>"
selectcommand="SELECT * FROM [Table1]"
insertcommand="INSERT INTO [Table1] ([CustomerRating]) VALUES (@CustomerRating)"
oninserting="SqlDataSource1_Inserting">
<insertparameters>
<asp:QueryStringParameter Name="CustomerRating"
QueryStringField="CustomerRating" Type="String" />
</insertparameters>
</asp:sqldatasource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False" DataKeyNames="id">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="CustomerRating" HeaderText="CustomerRating"
SortExpression="CustomerRating" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
AjaxControlToolkit.Rating Rating2 = (AjaxControlToolkit.Rating)FormView1.FindControl("Rating1");
e.Command.Parameters["@CustomerRating"].Value = Rating2.CurrentRating;
}
protected void Rating2_Changed2(object sender, AjaxControlToolkit.RatingEventArgs e)
{
int value = int.Parse(e.Value);
string result = string.Empty;
switch (value)
{
case 0:
SqlDataSource1.Insert();
break;
case 1:
SqlDataSource1.Insert();
break;
case 2:
SqlDataSource1.Insert();
break;
case 3:
SqlDataSource1.Insert();
break;
case 4:
SqlDataSource1.Insert();
break;
case 5:
SqlDataSource1.Insert();
break;
}
}
}
-Oleksandr-
Member
2 Points
17 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 11, 2008 03:25 PM|LINK
flyillusionA...
Member
4 Points
8 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 11, 2008 05:44 PM|LINK
-Oleksandr-
Member
2 Points
17 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 12, 2008 05:07 AM|LINK
flyillusionA...
Member
4 Points
8 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 12, 2008 09:15 PM|LINK
-Oleksandr-
Member
2 Points
17 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 13, 2008 08:08 PM|LINK
_(
Jonathan She...
All-Star
31269 Points
3445 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 15, 2008 01:01 PM|LINK
Hi Oleksandr,
Rating is designed for no posting back when select the same rate. So the solution for this is modify its source code.
_onStarClick : function(e) {
/// <summary>
/// Handler for a star's click event
/// </summary>
/// <param name="e" type="Sys.UI.DomEvent">
/// Event info
/// </param>
if (this._readOnly) {
return;
}
if (this._ratingValue != this._currentRating) {
this.set_Rating(this._currentRating);
}
},
set_Rating : function(value) {
if (this._ratingValue != value) {
this._ratingValue = value;
this._currentRating = value;
if (this.get_isInitialized()) {
if ((value < 0) || (value > this._maxRatingValue)) {
return;
}
this._update();
AjaxControlToolkit.RatingBehavior.callBaseMethod(this, 'set_ClientState', [ this._ratingValue ]);
this.raisePropertyChanged('Rating');
this.raiseRated(this._currentRating);
this._waitingMode(true);
var args = this._currentRating + ";" + this._tag;
var id = this._callbackID;
if (this._autoPostBack) {
__doPostBack(id, args);
}
else {
WebForm_DoCallback(id, args, this._receiveServerData, this, this._onError, true)
}
}
}
}
Best regards,
Jonathan
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
-Oleksandr-
Member
2 Points
17 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 16, 2008 06:41 AM|LINK
Thank you Jonathan!
And how can i integrated it in my code?
Jonathan She...
All-Star
31269 Points
3445 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 16, 2008 11:47 AM|LINK
Hi Oleksandr,
Actually, above is a part of RatingBehavior.js. To get the your goal, you shall modify the source code and recompile it. Now you can use it in your project.
Best regards,
Jonathan
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
-Oleksandr-
Member
2 Points
17 Posts
Re: Onclick() method in ajaxtoolkit control "Rating"
Apr 16, 2008 07:34 PM|LINK
I found it.
Now, what modify i must to do ?