Source Code

for file /controls/VBarChart.ascx

<%@ Control Language="C#" %>
<%
  // VBarChart.ascx
  // Implementation of the VBarChart AJAX Control.
  // Copyright (c) by Matthias Hertel, http://www.mathertel.de
  // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
  // ----- 
  // 09/17/2005 14:05:26 created by Matthias Hertel
%>
<script runat="server">
  // the names of the to be displayed properties
  private string _eventname = null;

  public string eventname
  {
    get { return _eventname; }
    set { _eventname = value; }
  }


  // the max. value of any property
  private int _maxvalue = 100;

  public int maxvalue
  {
    get { return _maxvalue; }
    set { _maxvalue = value; }
  }

  protected override void OnPreRender(EventArgs e)
  {
    base.OnPreRender(e);

    if (Page.Header == null)
      throw new Exception("The <head> element of this page is not marked with runat='server'.");

    // register the JavaScripts includes without need for a Form.
    if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "CommonBehaviour")) {
      Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "CommonBehaviour", String.Empty);
      ((HtmlHead)Page.Header).Controls.Add(new LiteralControl("<script type='text/javascript' src='"
        + Page.ResolveUrl("~/controls/jcl.js")
        + "'><" + "/script>\n"));
    } // if

    if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "VBarChartBehavior")) {
      Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "VBarChartBehavior", String.Empty);
      ((HtmlHead)Page.Header).Controls.Add(new LiteralControl("<script type='text/javascript' src='"
        + Page.ResolveUrl("~/controls/VBarChart.js")
        + "'><" + "/script>\n"));
    } // if

  } // OnPreRender
</script>
<!-- Here comes the HTML code that builds the Control. -->
<div id="<%=this.ClientID %>" class="VBARCHART" maxvalue="<%=this._maxvalue %>" eventname="<%=this._eventname %>"
  style="width:20px;height: 100px;background-color:blue ">
</div>
<!-- Here comes the script code to bind the behaviour. -->
<script defer="defer" type="text/javascript">
  jcl.LoadBehaviour("<%=this.ClientID %>", VBarChartBehavior);
</script>


This page is part of the http://www.mathertel.de/ web site.

For updates and discussions see http://ajaxaspects.blogspot.com/.