We help IT Professionals succeed at work.
Get Started

dynamic button not passing correct value to c# Web Method

Wayne Atherton
on
422 Views
Last Modified: 2015-04-07
I have a .js file that build a HTML table, within a carousel  - amongst other elements, is a <input> controlled, which displays text. The text can be altered by the end user, and derived from a read only element in the table.

So, for example, the  table  contains a field, called AcceptedText, the input control contains the value of this field, but allows the end user to add additional information.

Ok, so far so good. Now, what I need to do is add a submit button, to send the value of the input control to a C# WebMethod, And i've achieved this using the following code snippet:

 response +=  '<div class="pull-right">' +
    '<label>Accepted Text:</label><input type="text" id="acceptedText" value="' + tdata[i]['MatchedString'] + '"></input>' +
     '<button class="btn  btn-success btn-xs" type="button" data-toggle="tooltip" data-original-title="Add Text?" onclick=" addTextString(event, this, ' + tdata[i]['Id'] + '); " data-id="' + tdata[i]['Id'] + '" value="' + tdata[i]['MatchedString'] + '"></button>' +
                            '</div>' +

Open in new window


Now, every time the carousal changes, this input control changes value, but clicking on the button, always posted the first value. So, if there are four pages, then irrespective on where this button is clicked, I always get the value on page 1.

My WebMethod, looks like this:

function addTextString(event, element, id) {
    console.log($('#acceptedText').val());});

Open in new window


 
Not sure what i'm doing wrong, here, as the value in the input control is different, on each iteration of the carousel
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2013
Awarded 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE