using System;
using System.Web.UI;
using System.ComponentModel;
namespace Common.CTL.FocusManager
{
/// <summary>
/// clsFocusManager - Allows programmer to set focus to a control and to select the data in the
/// control if desired.
/// This web custom control is placed in the Tool Box.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:clsFocusManager runat=server></{0}:clsFocusManager>")]
public class clsFocusManager : System.Web.UI.WebControls.WebControl
{
private string mBoundControlID;
private bool mSelectControl;
//Property to indicate which control will receive focus.
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string BoundControlID
{
get
{
return mBoundControlID;
}
set
{
mBoundControlID = value;
}
}
//Property to indicate if the data in the control is selected or not.
[Bindable(true),
Category("Appearance"),
DefaultValue(false)]
public bool SelectControl
{
get
{
return mSelectControl;
}
set
{
mSelectControl = value;
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
string strScript;
if (mBoundControlID != null)
{
if (Page.FindControl(mBoundControlID) != null)
{
if(!Page.IsStartupScriptRegistered("FocusManager"))
{
strScript = "<Script Language=javascript>";
strScript += "document.getElementById('" + mBoundControlID + "').focus();";
if (mSelectControl == true)
{
strScript += "document.getElementById('" + mBoundControlID + "').select();";
}
strScript += "</script>";
Page.RegisterStartupScript("FocusManager", strScript);
}
}
}
}
}
}