|
using System;
using System.Resources;
using System.Reflection;
using System.Globalization;
using GlobalizationModule;
namespace MyWebApp
{
/// <summary>
/// Special LocalizeAttribute for localizing both
/// Text and ToolTip fields of a label.
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class TooltipLocalizerAttribute : LocalizeAttribute
{
public TooltipLocalizerAttribute()
{}
private string tooltipResourceName_;
/// <summary>
/// Name of the tooltip resource.
/// </summary>
public string ToolTipResourceName
{
get { return tooltipResourceName_; }
set { tooltipResourceName_ = value; }
}
/// <summary>
///
/// </summary>
public override void LocalizeObject(object target, System.Web.UI.Page page)
{
// User's page class is superclass of the ASP.NET page class
Type userPageClass = page.GetType().BaseType;
// The user's assembly is the one that holds his/her page class
Assembly targetAssembly = userPageClass.Assembly;
CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)target;
// Localize label's Text property
label.Text = (string)base.LoadResource(
this.ResourceName, culture, page, targetAssembly);
// Localize label's Tooltip property
label.ToolTip = (string)base.LoadResource(
this.ToolTipResourceName, culture, page, targetAssembly);
}
}
}
|
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.
Sami Vaaraniemi has been working as a software developer since 1990, primarily on Microsoft technologies. After 12 years of Win32 API and C++ he switched to .NET. He currently works as an independent consultant and can be contacted through his website at www.capehill.net.