0

I have a jQuery script like this:

var sList = "";
$('input[type=checkbox]').each(function () {
var sThisVal = (this.checked ? "1" : "0");
sList += (sList=="" ? sThisVal : "," + sThisVal);
});
console.log (sList);

But this script just writes sList values to console. How can I retrieve sList values in C# code? and use it.

3 Answers 3

2

Alternatively, if you don't want to do a full postback, you could consider using the ASP.NET AJAX Server Callback mechanism.

This will allow you to send your sList to a server-side web service, do whatever server-side processing you want, and then return the JSON-encoded result to the client.

Sign up to request clarification or add additional context in comments.

Comments

1

Add a hidden field:

<asp:HiddenField runat="server" ID="myList"/>

and write a JavaScript:

$("input[type=hidden][id$=myList]").val(sList);

and now you should get your sList on your server events, just see myList.Value from your C# code

1 Comment

Thank you, My reputation is not enough to score you.
0

you can simply add a hidden field to your asp.net page and set its value as a comma separated string using your JS function.

form the C# just get the data saved in the hidden field..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.