Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have try google but can't get a proper solution yet. I want get a label value in Datalist help of jquery. Because i want value get and save in database with page post back. I have try many way but can't success. i try add cssclass value find but all cssclass value find. like that our datalist have three record's when click the button three record's are showing, like 111618.
here is my code.
JavaScript
function upvote() {

         alert( $('myclass').text());


          $.ajax({
              type: "POST",
              url: "searchig-page-seeker.aspx/voteup",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (msg) {
                  if (msg.d == 'OnSuccess') {
                      alert("have a nice day");
                      return false;
                  }
                  else {
                      alert("have a no");
                      return false;
                  }
                  return false;
              }

          });
          return false;

      }


HTML datalist code

ASP.NET
<datalist>
<asp:Label ID="Label5" runat="server" CssClass="myclass" Text='<%#Eval("OrgJob_id")%>' ></asp:Label></datalist>


I want stackover flow vote up and down with page postback.
Posted

1 solution

You could do something like this:

ASP.NET
<asp:label id="Label5" runat="server" cssclass="myclass" text="<%#Eval("OrgJob_id")%>" onclick="upvote(this);return false;" xmlns:asp="#unknown"></asp:label>


JavaScript
function upvote(element) {
 
           alert( $(element).text());
            
        
            $.ajax({
                type: "POST",
                url: "searchig-page-seeker.aspx/voteup",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    if (msg.d == 'OnSuccess') {
                        alert("have a nice day");
                        return false;
                    }
                    else {
                        alert("have a no");
                        return false;
                    }
                    return false;
                }
 
            });
            return false;
           
        }


The 'element' parameter will contain the element that was clicked.
 
Share this answer
 
Comments
joginder-banger 6-Mar-14 23:54pm    
sorry for late reply and thanks for quick reply.i think this answer fifty % solve my problem. thanks sir,
Shelby Robertson 7-Mar-14 0:20am    
you are welcome
joginder-banger 7-Mar-14 0:37am    
sir if i bind the value of CommandArgument then how can get a value in java script like that mention below:-
<asp:ImageButton ID="Img_Up_vote" runat="server" OnClientClick="upvote(this); return false;"
ImageUrl="~/images/up.png" OnClick="Img_Up_vote_Click" CommandArgument='<%#Eval("OrgJob_id")%>' xmlns:asp="#unknown" />. When user click the up vote then get a jobid
Shelby Robertson 7-Mar-14 0:44am    
You can't that way, CommandArgument is never sent to the client. You could set an attribute that would get set like data-JobID='<%#Eval("OrgJob_id")%>'

Then in the javascript you can do something like var jobid = $(element).attr('data-JobID');
joginder-banger 7-Mar-14 1:10am    
thanks sir ...it's working....thanks a lot..sir your have a great knowledge about javascript and Jquery....sir where are you live means which country you belong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900