// <Snippet22> protected override void Render(HtmlTextWriter output) { output.Write("<br>This is the Text of SimpleWebControl : " + _Text); foreach (object attribute in (typeof(SimpleWebControl)).GetCustomAttributes(true)) { if (attribute is DataBindingHandlerAttribute) { DataBindingHandlerAttribute myDataBindingHandlerAttribute = (DataBindingHandlerAttribute)attribute; output.Write("<br><br><br>The IsDefaultAttribute of DataBindingHandlerAttribute is :" + myDataBindingHandlerAttribute.IsDefaultAttribute()); output.Write("<br><br><br>DataBinding HandlerTypeName:" + myDataBindingHandlerAttribute.HandlerTypeName); } } }
public static void Main() { System.ComponentModel.AttributeCollection myAttributes = TypeDescriptor.GetAttributes(typeof(SimpleWebControl)); DataBindingHandlerAttribute myDataBindingHandlerAttribute = myAttributes[typeof(DataBindingHandlerAttribute)] as DataBindingHandlerAttribute; if (myDataBindingHandlerAttribute != null) { Console.Write("DataBindingHandlerAttribute's HandlerTypeName is : " + myDataBindingHandlerAttribute.HandlerTypeName); } }
public static void Main() { try { // <Snippet1> DataBindingHandlerAttribute myDataBindingHandlerAttribute = DataBindingHandlerAttribute.Default; // </Snippet1> Console.WriteLine("Hash code for DataBindingHandlerAttribute instance is : " + myDataBindingHandlerAttribute.GetHashCode()); } catch (Exception e) { Console.WriteLine("Exception : " + e.Message); } }
public void TestDefaultConstructor() { DataBindingHandlerAttribute at = new DataBindingHandlerAttribute(); Assert.AreEqual(String.Empty, at.HandlerTypeName, "#01"); }
public void SetUp() { attr = new DataBindingHandlerAttribute(t); empty = DataBindingHandlerAttribute.Default; }
/// <include file='doc\GlobalDataBindingHandler.uex' path='docs/doc[@for="GlobalDataBindingHandler.OnDataBind"]/*' /> /// <devdoc> /// </devdoc> public static void OnDataBind(object sender, EventArgs e) { Debug.Assert(sender is Control, "DataBindings can only be present on Controls."); Control control = (Control)sender; // check if this control has any data-bindings IDataBindingsAccessor dataBindingsAccessor = (IDataBindingsAccessor)sender; if (dataBindingsAccessor.HasDataBindings == false) { return; } // check if the control type has an associated data-binding handler DataBindingHandlerAttribute handlerAttribute = (DataBindingHandlerAttribute)TypeDescriptor.GetAttributes(sender)[typeof(DataBindingHandlerAttribute)]; if ((handlerAttribute == null) || (handlerAttribute.HandlerTypeName.Length == 0)) { return; } // components in the designer/container do not get handled here; the // designer for that control handles it in its own special way ISite site = control.Site; IDesignerHost designerHost = null; if (site == null) { Page page = control.Page; if (page != null) { site = page.Site; } else { // When the designer is working on a UserControl instead of a Page Control parent = control.Parent; // We shouldn't have to walk up the parent chain a whole lot - maybe a couple // of levels on the average while ((site == null) && (parent != null)) { if (parent.Site != null) { site = parent.Site; } parent = parent.Parent; } } } if (site != null) { designerHost = (IDesignerHost)site.GetService(typeof(IDesignerHost)); } if (designerHost == null) { Debug.Fail("Did not get back an IDesignerHost"); return; } // non-top level components, such as controls within templates do not have designers // these are the only things that need the data-binding handler stuff IDesigner designer = designerHost.GetDesigner(control); if (designer != null) { return; } // get the handler and cache it the first time around DataBindingHandler dataBindingHandler = null; try { string handlerTypeName = handlerAttribute.HandlerTypeName; dataBindingHandler = (DataBindingHandler)DataBindingHandlerTable[handlerTypeName]; if (dataBindingHandler == null) { Type handlerType = Type.GetType(handlerTypeName); if (handlerType != null) { dataBindingHandler = (DataBindingHandler)Activator.CreateInstance(handlerType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null); DataBindingHandlerTable[handlerTypeName] = dataBindingHandler; } } } catch (Exception ex) { Debug.Fail(ex.ToString()); return; } // finally delegate to it to handle this particular control if (dataBindingHandler != null) { dataBindingHandler.DataBindControl(designerHost, control); } }
public void Default_Deny_Unrestricted() { DataBindingHandlerAttribute a = DataBindingHandlerAttribute.Default; Assert.AreEqual(String.Empty, a.HandlerTypeName, "HandlerTypeName"); }
public void CtorType_Deny_Unrestricted() { DataBindingHandlerAttribute a = new DataBindingHandlerAttribute(GetType()); Assert.IsTrue(a.HandlerTypeName.StartsWith("MonoCasTests.System.Web.UI.DataBindingHandlerAttributeCas"), "HandlerTypeName"); }
public void CtorString_Deny_Unrestricted() { DataBindingHandlerAttribute a = new DataBindingHandlerAttribute("mono"); Assert.AreEqual("mono", a.HandlerTypeName, "HandlerTypeName"); }
public void Ctor_Deny_Unrestricted() { DataBindingHandlerAttribute a = new DataBindingHandlerAttribute(); Assert.AreEqual(String.Empty, a.HandlerTypeName, "HandlerTypeName"); }
public static void OnDataBind(object sender, EventArgs e) { Control component = (Control)sender; IDataBindingsAccessor accessor = (IDataBindingsAccessor)sender; if (accessor.HasDataBindings) { DataBindingHandlerAttribute attribute = (DataBindingHandlerAttribute)TypeDescriptor.GetAttributes(sender)[typeof(DataBindingHandlerAttribute)]; if ((attribute != null) && (attribute.HandlerTypeName.Length != 0)) { ISite site = component.Site; IDesignerHost designerHost = null; if (site == null) { Page page = component.Page; if (page != null) { site = page.Site; } else { for (Control control2 = component.Parent; (site == null) && (control2 != null); control2 = control2.Parent) { if (control2.Site != null) { site = control2.Site; } } } } if (site != null) { designerHost = (IDesignerHost)site.GetService(typeof(IDesignerHost)); } if ((designerHost != null) && (designerHost.GetDesigner(component) == null)) { DataBindingHandler handler = null; try { string handlerTypeName = attribute.HandlerTypeName; handler = (DataBindingHandler)DataBindingHandlerTable[handlerTypeName]; if (handler == null) { Type type = Type.GetType(handlerTypeName); if (type != null) { handler = (DataBindingHandler)Activator.CreateInstance(type, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, null, null, null); DataBindingHandlerTable[handlerTypeName] = handler; } } } catch (Exception) { return; } if (handler != null) { handler.DataBindControl(designerHost, component); } } } } }