This example shows how to use the WebImageViewer and WebThumbnailViewer controls together in a composite ServerControl. This control builds the controls in the overridden CreateChildControls method, and this method is called in Page.OnInit by EnsureChildControls. If these two methods are not called in the Page's OnInit, the controls will not be able to use any asynchronous callbacks to get image tiles, thumbnails, or use RemoteInvoke
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Atalasoft.Imaging.WebControls;
using Atalasoft.Imaging.WebControls.Annotations;
namespace WebControlLibrary1
{
public class CustomCompositeControl : System.Web.UI.WebControls.WebControl, INamingContainer
{
private WebAnnotationViewer _annotationViewer = null;
private WebThumbnailViewer _thumbnailViewer = null;
// This constructor ensures that the composite control is rendered as div tag
public CustomCompositeControl()
: base(HtmlTextWriterTag.Div)
{
}
// This override creates the child controls for the composite control
// If you need to add other controls, such as tables, add them here
protected override void CreateChildControls()
{
try
{
base.CreateChildControls();
this._annotationViewer = new WebAnnotationViewer();
this._annotationViewer.ID = "MainViewer";
this._annotationViewer.AntialiasDisplay = AntialiasDisplayMode.ReductionOnly;
this._annotationViewer.Height = new Unit("500px");
this._annotationViewer.Width = new Unit("600px");
this._thumbnailViewer = new WebThumbnailViewer();
this._thumbnailViewer.ID = "Thumbnails";
this._thumbnailViewer.ViewerID = this._annotationViewer.ClientID;
this._thumbnailViewer.Height = new Unit("500px");
this._thumbnailViewer.Width = new Unit("160px");
this.Controls.Add(this._thumbnailViewer);
this.Controls.Add(this._annotationViewer);
}
catch (Exception e)
{
Label err = new Label();
err.Text = e.StackTrace;
this.Controls.Add(err);
}
}
// This call is needed so that the asynchronous callbacks have a path to follow
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.EnsureChildControls();
}
public void OpenUrl(string url)
{
this._thumbnailViewer.OpenUrl(url);
}
}
}