Initial ScriptControlDescriptor implementation
authorIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Tue, 26 Jun 2007 09:17:55 +0000 (09:17 -0000)
committerIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Tue, 26 Jun 2007 09:17:55 +0000 (09:17 -0000)
svn path=/trunk/mcs/; revision=80771

mcs/class/System.Web.Extensions/System.Web.UI/ScriptBehaviorDescriptor.cs
mcs/class/System.Web.Extensions/System.Web.UI/ScriptComponentDescriptor.cs
mcs/class/System.Web.Extensions/System.Web.UI/ScriptControlDescriptor.cs

index 2d60ee4768098653bb091645d25f8f02fb0170fe..31506523e22d6fcacd262a113fa9375bacd0e269 100644 (file)
@@ -35,14 +35,13 @@ namespace System.Web.UI
 {
        public class ScriptBehaviorDescriptor : ScriptComponentDescriptor
        {
-               string _elementID;
                string _name;
 
                public ScriptBehaviorDescriptor (string type, string elementID)
                        : base (type) {
                        if (String.IsNullOrEmpty (elementID))
                                throw new ArgumentException ("Value cannot be null or empty.", "elementID");
-                       _elementID = elementID;
+                       ElementIDInternal = elementID;
                }
 
                public override string ClientID {
@@ -56,7 +55,7 @@ namespace System.Web.UI
 
                public string ElementID {
                        get {
-                               return _elementID;
+                               return ElementIDInternal;
                        }
                }
 
@@ -80,7 +79,7 @@ namespace System.Web.UI
                }
 
                protected internal override string GetScript () {
-                       return String.Format ("$create({0}, {1}, {2}, {3}, $get(\"{4}\"));", Type, GetSerializedProperties (), GetSerializedEvents (), GetSerializedReferences (), ElementID);
+                       return base.GetScript ();
                }
        }
 }
index 7b904e5d250c78ecf191c65c707873e99996ac64..9b5c2c7b94ca06548115b098c1bf78729acdab36 100644 (file)
@@ -36,6 +36,7 @@ namespace System.Web.UI
 {
        public class ScriptComponentDescriptor : ScriptDescriptor
        {
+               string _elementID;
                string _type;
                string _id;
                Dictionary<string, string> _properties;
@@ -54,6 +55,15 @@ namespace System.Web.UI
                        }
                }
 
+               internal string ElementIDInternal {
+                       get {
+                               return _elementID;
+                       }
+                       set {
+                               _elementID = value;
+                       }
+               }
+
                public virtual string ID {
                        get {
                                if (_id == null)
@@ -132,7 +142,10 @@ namespace System.Web.UI
                }
 
                protected internal override string GetScript () {
-                       return String.Format ("$create({0}, {1}, {2}, {3});", Type, GetSerializedProperties (), GetSerializedEvents (), GetSerializedReferences ());
+                       if (String.IsNullOrEmpty (ElementIDInternal))
+                               return String.Format ("$create({0}, {1}, {2}, {3});", Type, GetSerializedProperties (), GetSerializedEvents (), GetSerializedReferences ());
+                       else
+                               return String.Format ("$create({0}, {1}, {2}, {3}, $get(\"{4}\"));", Type, GetSerializedProperties (), GetSerializedEvents (), GetSerializedReferences (), ElementIDInternal);
                }
 
                internal static string SerializeDictionary (Dictionary<string, string> dictionary) {
@@ -147,15 +160,15 @@ namespace System.Web.UI
                        return sb.ToString ();
                }
 
-               internal string GetSerializedProperties () {
+               string GetSerializedProperties () {
                        return SerializeDictionary (_properties);
                }
 
-               internal string GetSerializedEvents () {
+               string GetSerializedEvents () {
                        return SerializeDictionary (_events);
                }
 
-               internal string GetSerializedReferences () {
+               string GetSerializedReferences () {
                        return SerializeDictionary (_references);
                }
        }
index c2a82e15ca919ec6c056e46a5cb3002936b0ac28..9d9ede84059e40665c3044ce874853853dbb3d62 100644 (file)
@@ -37,27 +37,29 @@ namespace System.Web.UI
        {
                public ScriptControlDescriptor (string type, string elementID)
                        : base (type) {
-                       throw new NotImplementedException ();
+                       if (String.IsNullOrEmpty (elementID))
+                               throw new ArgumentException ("Value cannot be null or empty.", "elementID");
+                       ElementIDInternal = elementID;
                }
 
                public override string ClientID {
                        get {
-                               throw new NotImplementedException ();
+                               return ElementID;
                        }
                }
 
                public string ElementID {
                        get {
-                               throw new NotImplementedException ();
+                               return ElementIDInternal;
                        }
                }
 
                public override string ID {
                        get {
-                               throw new NotImplementedException ();
+                               return base.ID;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               throw new InvalidOperationException ("The 'ID' property on ScriptControlDescriptor is not settable. The client ID of a script control is always equal to its element ID.");
                        }
                }
        }