Storing the images in a hidden field

To use the images queried by the GetImages() method, in javascript, you must serialize them and store them as a string in a HiddenFieldcontrol.

To do this, you must add reference to the assembly System.Web.Extensions in the CoverFlowWidget project. You can find the assembly on .NET tab.

After adding the references, import the following using statement in the CoverFlow.cs file:

using System.Web.Script.Serialization;

Adding a HiddenField control to the template

Use a HiddenField control to store information on the client without the end-user to be able to see it. To add a HiddenField control, open the CoverFlow.ascx template file and insert the following code at the top:

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

Write down the ID value, because you will use it to access the control from the CoverFlow.cs code file.

Storing the images in the HiddenField control

To store the images in the HiddenField control, perform the following:

  1. In the InitializeControls override of the CoverFlow class, call the GetImages() method, and serialize its result with aJavaScriptSerializer.
  2. Get an instance of the HiddenField control.
  3. Set its Value property to the result from the serialization.

Following is the code for the InitializeControls method:

private HiddenField imagesField;
protected override void InitializeControls(GenericContainer container)
{
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    List<Hashtable> images = GetImages();
    string serializedCollection = serializer.Serialize(images);
 
    this.imagesField = container.GetControl<HiddenField>("imagesField", true);
    this.imagesField.Value = serializedCollection;
}

Next, pass the values stored in the string, to the Silverlight application via javascript. For more information, see Passing the images to the Silverlight via javascript.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK