{"id":111,"date":"2007-10-16T12:44:00","date_gmt":"2007-10-16T12:44:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2007\/10\/16\/attributes-to-consider-applying-when-writing-a-custom-control\/"},"modified":"2007-10-16T12:44:00","modified_gmt":"2007-10-16T12:44:00","slug":"attributes-to-consider-applying-when-writing-a-custom-control","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2007\/10\/16\/attributes-to-consider-applying-when-writing-a-custom-control\/","title":{"rendered":"Attributes to consider applying when writing a custom control"},"content":{"rendered":"<div>\n<div>\n<p><span lang=EN-US style='color:black'>The original author <a href=\"http:\/\/weblogs.asp.net\/leftslipper\/archive\/2007\/02\/15\/attributes-to-consider-applying-when-writing-a-custom-control.aspx\">published<\/a> this : <\/span><span lang=EN><a href=\"http:\/\/weblogs.asp.net\/leftslipper\/default.aspx\">Eilon Lipton&#8217;s Blog<\/a><o:p><\/o:p><\/span><\/p>\n<p><span lang=EN><o:p>&nbsp;<\/o:p><\/span><\/p>\n<p style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN>Almost every custom control has&nbsp;at least one additional public property, and&nbsp;that public property as well as the control itself should probably have at least a few attributes applied to them. Attributes tell the designer&nbsp;host (Visual Studio) or the parser (ASP.NET) interesting things about your control that might not be evident from just its name and its type. Launch any decent class browser tool and you&#8217;ll see that every control that shipped in ASP.NET and ASP.NET AJAX has several attributes on it as well as their properties and events.<o:p><\/o:p><\/span><\/p>\n<p style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN>By applying the proper set of attributes you can significantly increase the usefulness of your control in several ways. For example, the DescriptionAttribute provides helpful text to the person designing the page. The ValidationPropertyAttribute is required when the person designing the page wants to validate the value of your control. Following is a list of the most useful and important attributes you can apply to your control and its properties and events.<o:p><\/o:p><\/span><\/p>\n<p style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span lang=EN>Control attributes:<\/span><\/b><span lang=EN><o:p><\/o:p><\/span><\/p>\n<ul type=disc>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>ControlValueProperty<br \/>      &nbsp;&#8211; Used by data source parameters to get the &quot;intrinsic&quot;      value of the control. For example, DropDownList&#8217;s &quot;intrinsic&quot; value      is its SelectedValue property. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>DefaultEvent<br \/>      &nbsp;&#8211; Set the event for which to create an event handler when double      clicking the control in the designer. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>DefaultProperty<br \/>      &nbsp;&#8211; Set the default selected property in the designer&#8217;s property grid.      <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>NonVisualControl<br \/>      &nbsp;&#8211; Hide the control at design time when &quot;Non Visual      Controls&quot; is unchecked from the View menu. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>ParseChildren<br \/>      &nbsp;&#8211; The full name is really &quot;parse children as properties&quot;.<br \/>      &nbsp;&#8211; Set to true if the inner contents of the control represent      properties as opposed to child controls.<br \/>      &nbsp;&#8211; True by default on controls deriving from WebControl; false by      default otherwise. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>PersistChildren<br \/>      &nbsp;&#8211; The full name is really &quot;persist child controls&quot;.<br \/>      &nbsp;&#8211; Set to true if the designer should persist child controls as the      inner contents.<br \/>      &nbsp;&#8211; False by default on controls deriving from WebControl; true by      default otherwise.<br \/>      &nbsp;&#8211; 99.9% of the time PersistChildren has the opposite value of      ParseChildren. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>SupportsEventValidation<br \/>      &nbsp;&#8211; Indicates that the control&#8217;s client-side calls to __doPostBack()      should be validated on the server for security purposes. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>Themable<br \/>      &nbsp;&#8211; Indicates that by default all the control&#8217;s properties can be      customized via themes. Individual properties can also be marked with this      attribute to override the behavior.<br \/>      &nbsp;&#8211; True by default for controls that derive from WebControl. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>ValidationProperty<br \/>      &nbsp;&#8211; Required when a control can be validated.<br \/>      &nbsp;&#8211; Somewhat similar to the ControlValueProperty in that they often      point at the same property. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l0 level1 lfo1'><span lang=EN>ViewStateModeById<br \/>      &nbsp;&#8211; Indicates that viewstate should be loaded based on control IDs as      opposed to being loaded based on the index of the control in the child      controls collection.<o:p><\/o:p><\/span><\/li>\n<\/ul>\n<p style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span lang=EN>Property attributes:<\/span><\/b><span lang=EN><o:p><\/o:p><\/span><\/p>\n<ul type=disc>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>Bindable<br \/>      &nbsp;&#8211; Indicates at design time only whether the property should appear      by default in the Edit Databindings dialog. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>Browsable<br \/>      &nbsp;&#8211; Indicates whether the property is visible in the property grid at      design time. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>Category<br \/>      &nbsp;&#8211; Determines in which category the property will appear when the      property grid is in category mode. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>DefaultValue<br \/>      &nbsp;&#8211; Get-only property: Since get-only properties are never persisted      anyway, no default value is needed.<br \/>      &nbsp;&#8211; Get\/Set value type property: Must be set.<br \/>      &nbsp;&#8211; Get\/Set reference type property: Must be null so that it shows up      as non-bold in the property grid. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>Description<br \/>      &nbsp;&#8211; Determines the help text that will show in the property grid&#8217;s      lower help panel. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>DesignerSerializationVisibility<br \/>      &nbsp;&#8211; Controls whether the property is persisted in the markup (see also      PersistenceMode).<br \/>      &nbsp;&#8211; Use this to prevent get\/set properties from being persisted at      all. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>EditorBrowsable<br \/>      &nbsp;&#8211; Affects whether the property appears in Intellisense. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>IDReferenceProperty<br \/>      &nbsp;&#8211; Specifies that the property represents a control ID, and      optionally the type of the target control. Not used by Visual Studio&nbsp;2005.      <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>MergableProperty<br \/>      &nbsp;&#8211; Affects whether the property shows up in the property grid when      multiple controls are selected.<br \/>      &nbsp;&#8211; If the property is Browsable and is a reference type then set      Mergable=false (except immutable reference types,&nbsp;such as string). <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>PersistenceMode<br \/>      &nbsp;&#8211; Controls how the property is persisted in the markup.<br \/>      &nbsp;&#8211; Simple-valued properties should use the default, which is      Attribute.<br \/>      &nbsp;&#8211; Collection, template, and complex (e.g. styles) should use      InnerProperty.<br \/>      &nbsp;&#8211; InnerDefaultProperty should never be used since it causes      compatibility problems. For example, if in the next version of your      control you want another inner property, it won&#8217;t work properly.<br \/>      &nbsp;&#8211; EncodedInnerDefaultProperty should also rarely be used for similar      reasons as InnerDefaultProperty.<br \/>      &nbsp;&#8211; In ASP.NET 2.0 support was added for strings to be      InnerProperties, which is good for large multi-line string values, such as      XmlDataSource&#8217;s Data property. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l2 level1 lfo2'><span lang=EN>Themable<br \/>      &nbsp;&#8211; Overrides the value of the attribute on the control to determine      whether the property can be customized via themes.<o:p><\/o:p><\/span><\/li>\n<\/ul>\n<p style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span lang=EN>Event attributes:<\/span><\/b><span lang=EN><o:p><\/o:p><\/span><\/p>\n<ul type=disc>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l1 level1 lfo3'><span lang=EN>Browsable<br \/>      &nbsp;&#8211; Same as properties. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l1 level1 lfo3'><span lang=EN>Category<br \/>      &nbsp;&#8211; Same as properties. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l1 level1 lfo3'><span lang=EN>Description<br \/>      &nbsp;&#8211; Same as properties. <o:p><\/o:p><\/span><\/li>\n<li style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;      mso-list:l1 level1 lfo3'><span lang=EN>EditorBrowsable<br \/>      &nbsp;&#8211; Same as properties.<o:p><\/o:p><\/span><\/li>\n<\/ul>\n<p style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN><o:p>&nbsp;<\/o:p><\/span><\/p>\n<\/p><\/div>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The original author published this : Eilon Lipton&#8217;s Blog &nbsp; Almost every custom control has&nbsp;at least one additional public property, and&nbsp;that public property as well as the control itself should probably have at least a few attributes applied to them. Attributes tell the designer&nbsp;host (Visual Studio) or the parser (ASP.NET) interesting things about your control &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2007\/10\/16\/attributes-to-consider-applying-when-writing-a-custom-control\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Attributes to consider applying when writing a custom control&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":8,"uagb_excerpt":"The original author published this : Eilon Lipton&#8217;s Blog &nbsp; Almost every custom control has&nbsp;at least one additional public property, and&nbsp;that public property as well as the control itself should probably have at least a few attributes applied to them. Attributes tell the designer&nbsp;host (Visual Studio) or the parser (ASP.NET) interesting things about your control&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/111"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":0,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}