2 // System.Web.UI.HtmlControls.HtmlControl.cs
\r
5 // Bob Smith <bob@thestuff.net>
\r
12 using System.Globalization;
\r
14 using System.Web.UI;
\r
16 namespace System.Web.UI.HtmlControls{
\r
18 public abstract class HtmlControl : Control, IAttributeAccessor
\r
20 private string _tagName = "span";
\r
21 //TODO: Is this correct, or is the StateBag really the ViewState?
\r
22 private AttributeCollection _attributes = new AttributeCollection(new StateBag(true));
\r
23 private bool _disabled = false;
\r
25 public HtmlControl(){}
\r
27 public HtmlControl(string tag)
\r
29 if(tag != null && tag != String.Empty) _tagName = tag;
\r
32 internal static string AttributeToString(int n){
\r
33 if (n != -1)return n.ToString(NumberFormatInfo.InvariantInfo);
\r
37 internal static string AttributeToString(string s){
\r
38 if (s != null && s.Length != 0) return s;
\r
42 internal void PreProcessRelativeReference(HtmlTextWriter writer, string attribName){
\r
43 string attr = Attributes[attribName];
\r
45 if (attr.Length != 0){
\r
47 attr = ResolveUrl(attr);
\r
49 catch (Exception e) {
\r
50 throw new HttpException(attribName + " property had malformed url");
\r
52 writer.WriteAttribute(attribName, attr);
\r
53 Attributes.Remove(attribName);
\r
58 string System.Web.UI.IAttributeAccessor.GetAttribute(string name){
\r
59 return Attributes[name];
\r
62 void System.Web.UI.IAttributeAccessor.SetAttribute(string name, string value){
\r
63 Attributes[name] = value;
\r
66 protected virtual void RenderAttributes(HtmlTextWriter writer){
\r
68 writer.WriteAttribute("id",ClientID);
\r
70 Attributes.Render(writer);
\r
73 internal static void WriteOnClickAttribute(HtmlTextWriter writer, bool submitsAutomatically, bool submitsProgramatically, bool causesValidation) {
\r
78 AttributeCollection attr = Attributes;
\r
80 if (submitsAutomatically) {
\r
81 if ((causesValidation))
\r
82 local1 = System.Web.UI.Utils.GetClientValidateEvent(Page);
\r
84 else if (submitsProgramatically) {
\r
85 if (causesValidation)
\r
86 local1 = System.Web.UI.Utils.GetClientValidatedPostback(this);
\r
88 local1 = Page.GetPostBackClientEvent(this, String.Empty);
\r
90 if (local1 != null) {
\r
91 local2 = attr["language"];
\r
93 attr.Remove("language");
\r
94 writer.WriteAttribute("language", "javascript");
\r
95 local3 = attr["onclick"];
\r
96 if (local3 != null) {
\r
97 attr.Remove("onclick");
\r
98 writer.WriteAttribute("onclick", local3 + " " + local1);
\r
101 writer.WriteAttribute("onclick", local1);
\r
105 public AttributeCollection Attributes
\r
109 return _attributes;
\r
112 public bool Disabled
\r
123 public CssStyleCollection Style
\r
127 return _attributes.CssStyle;
\r
130 public virtual string TagName
\r