Skip to content

Instantly share code, notes, and snippets.

@vgrem
Created March 25, 2013 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/5238700 to your computer and use it in GitHub Desktop.
Save vgrem/5238700 to your computer and use it in GitHub Desktop.
public class SendAlertsManager : UserControl
{
#region Control Lifecycle
protected override void OnLoad(EventArgs e)
{
if (IsAlertNewPage || IsAlertEditPage)
{
EnableSendAlertsToSPGroup();
Visible = true;
}
else
{
Visible = false;
}
}
private void EnableSendAlertsToSPGroup()
{
var pe = FindControl<PeopleEditor>(Page.Controls);
if(pe!= null)
{
if(!pe.SelectionSet.Contains("SPGroup"))
{
pe.SelectionSet += ",SPGroup";
//pe.AfterCallbackClientScript = "expandGroupCallback";
}
}
}
protected override void OnPreRender(EventArgs e)
{
EnableSendAlertsToSPGroup();
base.OnPreRender(e);
}
#endregion
#region Control Utilities
/// <summary>
/// Find control recursivelly
/// (http://weblogs.asp.net/eporter/archive/2007/02/24/asp-net-findcontrol-recursive-with-generics.aspx)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="controls"></param>
/// <returns></returns>
public static T FindControl<T>(System.Web.UI.ControlCollection controls) where T : class
{
T found = default(T);
if (controls != null && controls.Count > 0)
{
for (int i = 0; i < controls.Count; i++)
{
if (found != null) break;
if (controls[i] is T)
{
found = controls[i] as T;
break;
}
found = FindControl<T>(controls[i].Controls);
}
}
return found;
}
#endregion
#region Properties
private bool IsAlertNewPage
{
get
{
return
(Context.Request.Url.PathAndQuery.IndexOf("_layouts/subnew.aspx",
StringComparison.InvariantCultureIgnoreCase) > 0);
}
}
private bool IsAlertEditPage
{
get
{
return
(Context.Request.Url.PathAndQuery.IndexOf("_layouts/subedit.aspx",
StringComparison.InvariantCultureIgnoreCase) > 0);
}
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment