Make HTML controls discoverable in Volta Control
When a Volta control is rendered, the ID attribute of the generated HTML is changed to something like _vcId_1_DivName which is inconvenient to find from code. But the ID attribute stays the same in case of Volta Page, so it is discoverable by ID like this:
Div divContent = Document.GetById<Div>("divContent");
However, if you add HTML controls to the control like the following, the ID is not changed during the rendering:
public VoltaControl1() : base("VoltaControl1.html") { InitializeComponent(); Button btnClick = new Button(); btnClick.InnerText = "Click!"; btnClick.Id = "btnClick"; this.Add(btnClick); }
If you don’t prefer this way and seriously want to write your own HTML in the control’s html page, you might find the following snippet useful. But, remember in this case you will use name attribute of the html element instead of ID.
// Usage: var element = GetElementByName(Document.GetElementsByTagName("div"), "divWidget"); private HtmlElement GetElementByName(HtmlElementCollection elements, string name) { foreach (var element in elements) { DomAttribute nameAttribute = element.Attributes.GetNamedItem("name"); if (nameAttribute != null) if (nameAttribute.Value == name) return element; } return null; }
Making cross domain AJAX call using Volta
Making a cross domain AJAX call in Volta is piece of cake. Volta compiler generates necessary client codes to make it work. Here is a snippet that can make an AJAX call to some Url and fetch data:
public void DownloadPhotos() { IHttpRequest request = HttpRequestFactory.Create(); request.AsyncSend("POST", URL, string.Empty, delegate(string response) { OnPhotosLoaded(new PhotosLoadedEventArgs(response)); }); }
Both IHttpRequest and HttpRequestFactory classes can be found in the Microsoft.LiveLabs.Volta.MultiTier namespace. AsyncSend method performs the asynchronous call and calls back the delegate defined where OnPhotosLoaded event is fired to notify the subscriber of this event that the data has just arrived.

