0
votes

var data = $("#list2 li").map(function () { return $(this).children().html(); }).get();

the data variable contains the values that are fetched using jquery

can anyone suggest me the way how can i use this array in code behind class of the web page on button .click event my button is aspx control (runat ="server") as

script type="text/javascript">

function eOrder() { var data = $("#list1 li").map(function () { return $(this).children().html(); }).get(); debugger; };

<div style="clear:both;"></div>

</div>
<asp:Button ID="btnSave" runat="server" Text="Save" />

the values in the list are generated dynam,ically on Page_Load method

li = new HtmlGenericControl("li"); div = new HtmlGenericControl("div"); div.InnerText = webpart.DisplayTitle; li.Controls.Add(div); list2.Controls.Add(li);

& the list is also runat= "server"

basically i need to send the data array in code behind class on btnSave click

thankx in advance

2
11% chance you get a good answer I guess.jAndy
I wish I saw that before I answered:)Stilgar

2 Answers

0
votes

Simplest way is to add a HiddenField on your page and use jQuery to set its value to the string of the array. Then in code behind you use JSON deserializer to turn the string into an array of some type.

For deserialization you can use the JSON features provided by the .NET Framework: http://msdn.microsoft.com/en-us/library/bb412179.aspx This is a bit more complex but does not add dependencies to your project.

Alternatively you can use the increasingly popular JSON.NET. It seems easier to use but is an additional dependecy to your project. You probably want to use it if you do a lot of JSON work serverside.

-1
votes

Think you could use Ajax here jQuery.ajax