public TemplatedControl() { TemplateAttribute templateAttribute = AttributeSearcher.GetAttribute <TemplateAttribute>(GetType()); if (templateAttribute != null) { LoadTemplate(templateAttribute.FileName); } }
private IList <TemplateElementAttribute> GetBindableMembers() { List <TemplateElementAttribute> list = new List <TemplateElementAttribute>(); Type type = GetType(); while (type != typeof(TemplatedControl)) { list.AddRange(AttributeSearcher.GetMemberAttributes <TemplateElementAttribute>(type, false)); type = type.BaseType; } return(list); }
private void LoadTemplate(string templateFile) { _templateFile = templateFile; ITemplate ascx = GetTemplate(_templateFile); Controls.Clear(); ascx.InstantiateIn(this); Controls[0].ID = "_"; _templateElements = AttributeSearcher.GetMemberAttributes <TemplateElementAttribute>(GetType(), true); BindTemplateElements(false); }
protected void BindMemberControls(Control container) { foreach (TemplateElementAttribute element in AttributeSearcher.GetMemberAttributes <TemplateElementAttribute>(this.GetType(), false)) { Control control = ControlsSearcher.FindControl(container, element.ID); if (control == null && !element.CanBeNull) { throw new InvalidOperationException(String.Format("Element {0} not found in parent control {1}", element.ID, control.ID)); } else { element[this] = control; } } }