Chris N.P.
Chris N.P.

Reputation: 783

How to pass the value of a list or an array from code behind to jquery?

Let's say I want to scan my local drive or a particular local folder for all images. What I want to do is get all the location of all the images and store it in a list/array then after that JQuery will going to refer to the list/array for a slideshow.

Please help me with this.

Upvotes: 0

Views: 286

Answers (1)

CodingIntrigue
CodingIntrigue

Reputation: 78525

Putting this in your .aspx should do the trick. You can then reference imageList from your included Javascript. You need to include a reference to System.Web.Extensions.dll for JavaScriptSerializer

.aspx Page:

<html>
<head>
<script>
    var imageList = <%=new JavaScriptSerializer().Serialize(System.IO.Directory.GetFiles(@"C:\MyImages\", "*.png")) %>
    for(var i in imageList) {
        console.log(imageList[i]);
    }
</script>
...
</html>

Upvotes: 1

Related Questions