locked
problem in the rating RRS feed

  • Question

  • User-62667992 posted

    hiiii everyone

    im trying to do  the rating control ,i want the rating to be stored in the database so i implemented the onchanged event but when i click it nothing added to the database it wont work check the code please

     <ajaxToolkit:Rating ID="Rating1" runat="server" AutoPostBack="true" OnChanged="Rating1_Changed"  StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
        FilledStarCssClass="FilledStar"></ajaxToolkit:Rating>

    here is the code behind

    protected void Rating1_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
            {
                string constr = ConfigurationManager.ConnectionStrings[1].ConnectionString;
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand("INSERT INTO Rating VALUES (@rating,@id)"))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.CommandType = CommandType.Text;
                            cmd.Parameters.AddWithValue("@rating", e.Value);
                            cmd.Parameters.AddWithValue("@id", Request.QueryString["pla"].ToString());
                            cmd.Connection = con;
                            con.Open();
                            cmd.ExecuteNonQuery();
                            con.Close();
                        }
                    }
                }
                
                Response.Redirect(Request.Url.AbsoluteUri);
            }
    
    
    

      but nothing is happening i dont where is the problem?

    Wednesday, June 29, 2016 9:02 AM

All replies

  • User61956409 posted

    Hi arwa55,

    Firstly, please debug your code to make sure if Rating1_Changed event could fire.

    Secondly, please make sure if the insert query is correct. You could try to specify both the column names and the values to be inserted.

    SqlCommand cmd = new SqlCommand("INSERT INTO Rating (rating,id) VALUES (@rating,@id)")

    Besides, this article explained how to save and update the User Ratings in Database using AJAX Control Toolkit Rating Extender Control, you could refer to it.

    http://www.aspsnippets.com/Articles/ASPNet-AJAX-Rating-Control-Example.aspx

    Best Regards,

    Fei Han

    Thursday, June 30, 2016 7:43 AM
  • User-62667992 posted

    you are right fie han the Rating1_Changed event wont fire 

    ive no idea why i added autopostback=true still it wont fire

    wat do u think is the problem?

    Thursday, June 30, 2016 9:26 AM
  • User61956409 posted

    Hi arwa55,

    Firstly, you could try to upgrade AjaxControlToolkit to the latest version.

    https://ajaxcontroltoolkit.codeplex.com/documentation  

    Secondly, I’d like to know if display Ratings in the Rating Extender control in your web page. And you could download complete demo from the following link and compare the example with your code.

    http://www.aspsnippets.com/Articles/ASPNet-AJAX-Rating-Control-Example.aspx

    Best Regards,

    Fei Han

    Friday, July 1, 2016 9:59 AM
  • User-62667992 posted

    hii

    i did upgraded a while ago to 15.1 

    and yes the control is displayed on the screen

    also yes i used this link to implement the rating control

    http://www.aspsnippets.com/Articles/ASPNet-AJAX-Rating-Control-Example.aspx

    i feel may be the control is bugged or smthing??

    Sunday, July 3, 2016 7:44 AM
  • User61956409 posted

    Hi arwa55,

    Please check the html markup of Rating Extender control using F12 developer tools to make use if it could be rendered in browser. Besides, please make sure if you specify and implement StarCssClass, WaitingStarCssClass and EmptyStarCssClass in your CSS file.

    Best Regards,

    Fei Han

    Friday, July 8, 2016 8:36 AM
  • User-62667992 posted

    hiii fei han 

    i did all what you said but still im getting the problem

    Monday, August 15, 2016 8:01 AM
  • User-62667992 posted

    hi everyone 

    i m trying to figure this out what i concluded that the onchanged event doesnt fire cause whatever i put in the "Rating1_Changed" nothing happen

    im thinking may be somthing relate to the ajax toolkit configuration but i couldn't findanything

    Tuesday, August 16, 2016 9:27 AM
  • User-62667992 posted

    hiiiii agaaaain

    i got it work by removing autopostback="true" 

    but the event fires twice 

    now wat 

    Tuesday, August 16, 2016 2:51 PM