How to access Cache images loaded Serverside and retrieved on Client

peter liles 556 Reputation points
2022-09-28T16:00:04.887+00:00

I have server side code that retrieved images from table and stores them in a Dictionary array and in Cache memory like:

Cache("files") = New Dictionary(Of String, String)()

The 'Of string' key is identity number of image to add and the String() value contain the corresponding image in Base64string format.

I now would like to be able to retrieve a particular image from the Cache Dictionary array by passing ID number to javascript function and load that image in a image element on page from client.

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-09-29T02:52:25.537+00:00

    Hi @peter liles ,
    Where are you currently having problems?
    If you want to use javascript to get the value of the backend, you can try the following method.
    1.Create a property in your code behind

    protected string MyProperty { get { return "your value"; } }  
    

    then in javascript

    var myValue = "<%= MyProperty %>";  
    

    2.You can use an ASP.Net HiddenField. You just set its value on the server and retrieve it via javascript when you need it.
    Serverside

    hdf_Test.Value = "yourValue";  
    

    HTML

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

    Javascript

    document.getElementById('hdf_Test').value  
    

    3.Retrieve the value with an AJAX request.

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.