Onclick() method in ajaxtoolkit control "Rating"

Last post 04-17-2008 10:59 AM by Jonathan Shen – MSFT. 12 replies.

Sort Posts:

  • Onclick() method in ajaxtoolkit control "Rating"

    04-11-2008, 3:15 AM
    • Member
      2 point Member
    • -Oleksandr-
    • Member since 04-11-2008, 6:55 AM
    • Posts 17

     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;

             }


           
        }
      
    }
     

     

     

  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-11-2008, 11:25 AM
    • Member
      2 point Member
    • -Oleksandr-
    • Member since 04-11-2008, 6:55 AM
    • Posts 17
    Peoples, help plz
  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-11-2008, 1:44 PM
    I have the same problem!!! Can anybody propose the solution?
  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-12-2008, 1:07 AM
    • Member
      2 point Member
    • -Oleksandr-
    • Member since 04-11-2008, 6:55 AM
    • Posts 17
    ?
  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-12-2008, 5:15 PM
    Any ideas
  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-13-2008, 4:08 PM
    • Member
      2 point Member
    • -Oleksandr-
    • Member since 04-11-2008, 6:55 AM
    • Posts 17

     _(

  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-15-2008, 9:01 AM
    Answer

    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

    Jonathan Shen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-16-2008, 2:41 AM
    • Member
      2 point Member
    • -Oleksandr-
    • Member since 04-11-2008, 6:55 AM
    • Posts 17

     Thank you Jonathan!

    And how can i integrated it in my code?

  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-16-2008, 7:47 AM

    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

    Jonathan Shen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-16-2008, 3:34 PM
    • Member
      2 point Member
    • -Oleksandr-
    • Member since 04-11-2008, 6:55 AM
    • Posts 17

     I found it.

    Now, what modify i must to do ?

  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-16-2008, 10:07 PM

    Hi Oleksandr,

    Remove the bold parts away and recompile it. We suggest that you'd better dip into its source code.

    Best regards,

    Jonathan

    Jonathan Shen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-17-2008, 2:49 AM
    • Member
      2 point Member
    • -Oleksandr-
    • Member since 04-11-2008, 6:55 AM
    • Posts 17

     I understand, but i dont know java well.

    Can you help me and write this modify ?

  • Re: Onclick() method in ajaxtoolkit control "Rating"

    04-17-2008, 10:59 AM

    Hi  Oleksandr,

    -Oleksandr-:
    Can you help me and write this modify ?

    I'm really sorry to say that this forum is a place to discuss the technical issues rather than write full solution(samples).  We suggest that you'd better modify it by yourself.  You will find more during the process.   Any further questions, please feel free to let me know.

    Best regards,

    Jonathan

    Jonathan Shen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (13 items)