Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:23:06+00:00 2026-06-08T11:23:06+00:00

I have some code in JavaScript like this: slider.setPhotos([ { src: image1, name: n1

  • 0

I have some code in JavaScript like this:

slider.setPhotos([
    { "src": "image1", "name": "n1" },
    { "src": "image2", "name": "n2" },
    { "src": "image3", "name": "n3" }
    ]);

And I want to set the values of src and name from C#.

Assume values are like this in C#:

var images = new string[] {"/images/a1.jpg", "/images/a2.jpg", "/images/a3.jpg"};

var names = new string[] {"First", "Second", "Third"};

How can I set these values into JavaScript code (i.e. in Page Load method in C# code)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:23:09+00:00Added an answer on June 8, 2026 at 11:23 am

    On the server you need to serialize the data as JSON and then you can write it into the response as HTML using something like a hidden input field.

    For example you might use the NewtonSoft JSON library to serialize the JSON (which is built into ASP MVC 4 however is easy to install using Nuget)

    string json = Newtonsoft.Json.JsonConvert.SerializeObject(images);
    

    Then render the json into the HTML (there are number of methods to do this)
    e.g.

    Response.Write(string.Concat("<input id='data' type='hidden' value='", json, "' />");
    

    or

    HiddenField jsonField = new HiddenField
    {
        ID = "data"
    };
    jsonField.Value = json;
    this.Controls.Add(jsonField);
    

    or even write directly as script skipping the need to parse on the client (I still tend to use the HTML method to avoid any issues with Postbacks/Update Panels causing the script to be executed multiple times)

    Response.Write(string.Concat("<script type='text/javascript'> var images = ", json, ";</script>");
    

    On the client you can then read this JSON from the HTML and parse it. In modern browsers this is built in, or you can polyfill with something like JSON2

    e.g.

    var field = document.getElenentById('data');
    var images = JSON.parse(field.value);
    

    You then have access to the data as a Javascript object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have javascript code some thing like this -- var count=3; var pl=new Array(count);
I have got some javascript code and I'd like to convert this to C#.
I have a javascript file which has some code somewhat like this: var Slide
I have some javascript code like this, var worker = new Worker(javascript/worker.js); worker.onmessage =
i have some javascript code in Django templates like this <script type=text/javascript> pager.init(); pager.showPageNav('pager',
In my aspx file, I have some code that looks like this: <script type=text/javascript>
I have some code a little like this... <img src=... width=100 height=100 alt= onclick=FlipImg(1234)
I have some simple javascript code that looks like this: var divLink = $(this).attr(href);
I have some very simple javascript code that looks like this: var newWindow =
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.