2 // System.Web.UI.HtmlControls.HtmlControl.cs
5 // Bob Smith <bob@thestuff.net>
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ComponentModel;
32 using System.ComponentModel.Design;
33 using System.Globalization;
34 using System.Security.Permissions;
36 namespace System.Web.UI.HtmlControls{
39 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43 [Designer ("System.Web.UI.Design.HtmlIntrinsicControlDesigner, " + Consts.AssemblySystem_Design,
44 "System.ComponentModel.Design.IDesigner")]
45 public abstract class HtmlControl : Control, IAttributeAccessor
47 internal string _tagName;
48 private AttributeCollection _attributes;
56 HtmlControl() : this ("span") {}
63 HtmlControl(string tag)
68 protected override ControlCollection CreateControlCollection ()
70 return new EmptyControlCollection (this);
73 internal static string AttributeToString(int n){
74 if (n != -1)return n.ToString(NumberFormatInfo.InvariantInfo);
78 internal static string AttributeToString(string s){
79 if (s != null && s.Length != 0) return s;
83 internal void PreProcessRelativeReference(HtmlTextWriter writer, string attribName){
84 string attr = Attributes[attribName];
86 if (attr.Length != 0){
88 attr = ResolveUrl(attr);
91 throw new HttpException(attribName + " property had malformed url");
93 writer.WriteAttribute(attribName, attr);
94 Attributes.Remove(attribName);
100 /* keep these two methods in sync with the
101 * IAttributeAccessor iface methods below */
102 protected virtual string GetAttribute (string name)
104 return Attributes[name];
107 protected virtual void SetAttribute (string name, string value)
109 Attributes[name] = value;
113 string System.Web.UI.IAttributeAccessor.GetAttribute(string name){
114 return Attributes[name];
117 void System.Web.UI.IAttributeAccessor.SetAttribute(string name, string value){
118 Attributes[name] = value;
121 protected virtual void RenderBeginTag (HtmlTextWriter writer)
123 writer.WriteBeginTag (TagName);
124 RenderAttributes (writer);
133 override void Render (HtmlTextWriter writer)
135 RenderBeginTag (writer);
138 protected virtual void RenderAttributes(HtmlTextWriter writer){
140 writer.WriteAttribute("id",ClientID);
142 Attributes.Render(writer);
146 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
147 public AttributeCollection Attributes
150 if (_attributes == null)
151 _attributes = new AttributeCollection (ViewState);
156 [DefaultValue(false)]
157 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
158 [WebSysDescription("")]
159 [WebCategory("Behavior")]
161 [TypeConverter (typeof(MinimizableAttributeTypeConverter))]
166 string disableAttr = Attributes["disabled"] as string;
167 return (disableAttr != null);
171 Attributes.Remove ("disabled");
173 Attributes["disabled"] = "disabled";
178 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
179 public CssStyleCollection Style
181 get { return Attributes.CssStyle; }
185 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
186 [WebSysDescription("")]
187 [WebCategory("Appearance")]
188 public virtual string TagName
190 get { return _tagName; }
193 protected override bool ViewStateIgnoresCase