|
// -- FILE ------------------------------------------------------------------
// name : AdapterControl.cs
// project : Itenso Script Panel
// created : Jani Giannoudis - 2012.03.29
// language : c#
// environment: .NET 4.0
// copyright : (c) 2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Itenso.Community.AdapterControl.Controls
{
// ------------------------------------------------------------------------
public class AdapterControl : Control
{
// ----------------------------------------------------------------------
public enum AdaptMode
{
None,
Unvaried,
Inverted,
} // enum AdaptMode
// ----------------------------------------------------------------------
[Themeable( false )]
public string SourceControl { get; set; }
// ----------------------------------------------------------------------
[Themeable( false )]
public string TargetControl { get; set; }
// ----------------------------------------------------------------------
[Themeable( false )]
public AdaptMode EnabledMode { get; set; }
// ----------------------------------------------------------------------
[Themeable( false )]
public AdaptMode VisibleMode { get; set; }
// ----------------------------------------------------------------------
protected override void OnPreRender( EventArgs e )
{
base.OnPreRender( e );
// source
if ( string.IsNullOrEmpty( SourceControl ) )
{
Trace.WriteLine( "AdapterControl: missing source control" );
return;
}
Control source = Parent.FindControl( SourceControl );
if ( source == null )
{
Trace.WriteLine( "AdapterControl: source control '" + SourceControl + "' not found" );
return;
}
// target
if ( string.IsNullOrEmpty( TargetControl ) )
{
Trace.WriteLine( "AdapterControl: missing target control" );
return;
}
Control target = Parent.FindControl( TargetControl );
if ( target == null )
{
Trace.WriteLine( "AdapterControl: target control '" + TargetControl + "' not found" );
return;
}
switch ( VisibleMode )
{
case AdaptMode.Unvaried:
target.Visible = source.Visible;
break;
case AdaptMode.Inverted:
target.Visible = !source.Visible;
break;
}
if ( target.Visible && EnabledMode != AdaptMode.None )
{
WebControl sourceWebControl = source as WebControl;
WebControl targetWebControl = target as WebControl;
if ( sourceWebControl != null && targetWebControl != null )
{
switch ( EnabledMode )
{
case AdaptMode.Unvaried:
targetWebControl.Enabled = sourceWebControl.Enabled;
break;
case AdaptMode.Inverted:
targetWebControl.Enabled = !sourceWebControl.Enabled;
break;
}
}
}
} // OnPreRender
} // class AdapterControl
} // namespace Itenso.Community.AdapterControl.Controls
// -- EOF -------------------------------------------------------------------
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.