DotImage Knowledgebase

Home : Using WebControls in a Composite Server Control
Q10204 - HOWTO: Using WebControls in a Composite Server Control

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);
  }

 }
}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2013. InstantASP Ltd. All Rights Reserved

preload preload preload