0

I have a gridview with each row containing star rating, When the user clicks save on a row it should update the rating value to the database using ajax, i am using the code from http://rateit.codeplex.com to implement rating. so i need to use a div in each row with the given class as below

            <asp:TemplateField HeaderText="rate" HeaderStyle-HorizontalAlign="Left">
            <ItemTemplate>
                <div class="rateit" id="divrate"></div>
            </ItemTemplate>
        </asp:TemplateField>

and the save button is this

            <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton ID="imgSave" OnClientClick="javascript:return SaveItem(<% Eval("ID") %>, <% divrate.ClientID( %>);" runat="server" ImageUrl="~/Imgs/Yes.gif" AlternateText="Save"  />
            </ItemTemplate>
        </asp:TemplateField>

and the javascript function is

function SaveItem(RowID,RatingControlID){

         var ri = $(RatingControlID);
         var value = ri.rateit('value'); //rateit is the class used in div

         $.ajax({
             url: 'rateit.aspx', //save function
             data: { id: RowID, value: value }, 
             type: 'POST',
             success: function (data) {
                 $('#response').append('<li>' + data + '</li>');

             },
             error: function (jxhr, msg, err) {
                 $('#response').append('<li style="color:red">' + msg + '</li>');
             }
         });
     });

But in the function call itself it gives error

Jim Yarbro
  • 2,063
  • 15
  • 21
sjd
  • 1,329
  • 4
  • 28
  • 48

1 Answers1

0

You didn't terminate your ClientID call:

OnClientClick="javascript:return SaveItem(<% Eval("ID") %>, <% divrate.ClientID( %>);"

becomes:

OnClientClick="javascript:return SaveItem(<% Eval("ID") %>, <% divrate.ClientID() %>);"
Jim Yarbro
  • 2,063
  • 15
  • 21
  • fixed it but now the error is "Server tags cannot contain <% ... %> constructs." – sjd Oct 29 '13 at 16:15
  • Oh, sorry didn't even notice it was an asp control in the second template. yeah you can try to make your own control if you want that outputs the string with the variables included, but this is one of those situations where I would suggest just making an image button manually with HTML. http://stackoverflow.com/questions/11772326/submit-button-image – Jim Yarbro Oct 29 '13 at 17:09
  • i used an input type image. now the error is "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." is it possible to use a hidden control and refer it in the javascript function? – sjd Oct 29 '13 at 17:58