开发者

use dynamically generated array (jquery) in code behind class

开发者 https://www.devze.com 2023-02-10 09:38 出处:网络
var data = $(\"#list2 li\").map(function () { return $(this).children().html(); }).get(); the data variable contains the values that are fetched using jquery

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 c开发者_如何转开发ode 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


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.


Think you could use Ajax here jQuery.ajax

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号