Switch to compiler-tester
[mono.git] / mcs / class / System.Web / System.Web.UI / Page.cs
index 985d1d0161b5fca78e6840e882c5236d6968a741..8f5efede3efd0d31f0884692e7568d8eb98d9042 100755 (executable)
@@ -46,6 +46,9 @@ using System.Web;
 using System.Web.Caching;
 using System.Web.SessionState;
 using System.Web.Util;
+#if NET_2_0
+using System.Web.UI.HtmlControls;
+#endif
 
 namespace System.Web.UI
 {
@@ -55,7 +58,7 @@ namespace System.Web.UI
 #endif
 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
 [ToolboxItem (false)]
-[Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
+[Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
 public class Page : TemplateControl, IHttpHandler
 {
        private bool _viewState = true;
@@ -79,7 +82,7 @@ public class Page : TemplateControl, IHttpHandler
        string viewStateUserKey;
        NameValueCollection _requestValueCollection;
        string clientTarget;
-       ClientScriptManager scriptManager = new ClientScriptManager ();
+       ClientScriptManager scriptManager;
 
        [EditorBrowsable (EditorBrowsableState.Never)]
        protected const string postEventArgumentID = "__EVENTARGUMENT";
@@ -87,9 +90,9 @@ public class Page : TemplateControl, IHttpHandler
        protected const string postEventSourceID = "__EVENTTARGET";
 
 #if NET_2_0
-       private const string callbackArgumentID = "__CALLBACKARGUMENT";
-       private const string callbackSourceID = "__CALLBACKTARGET";
-       private const string previousPageID = "__PREVIOUSPAGE";
+       internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
+       internal const string CallbackSourceID = "__CALLBACKTARGET";
+       internal const string PreviousPageID = "__PREVIOUSPAGE";
        
        IPageHeader htmlHeader;
        
@@ -100,11 +103,13 @@ public class Page : TemplateControl, IHttpHandler
        bool isCrossPagePostBack;
        ArrayList requireStateControls;
        Hashtable _validatorsByGroup;
+       HtmlForm _form;
 #endif
 
        #region Constructor
        public Page ()
        {
+               scriptManager = new ClientScriptManager (this);
                Page = this;
        }
 
@@ -531,30 +536,41 @@ public class Page : TemplateControl, IHttpHandler
 
                return coll;
        }
-       
+
+#if NET_2_0
+       [Obsolete]
+#endif
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        public string GetPostBackClientEvent (Control control, string argument)
        {
-               return GetPostBackEventReference (control, argument);
+               return scriptManager.GetPostBackClientEvent (control, argument);
        }
 
+#if NET_2_0
+       [Obsolete]
+#endif
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        public string GetPostBackClientHyperlink (Control control, string argument)
        {
-               return "javascript:" + GetPostBackEventReference (control, argument);
+               return scriptManager.GetPostBackClientHyperlink (control, argument);
        }
 
+#if NET_2_0
+       [Obsolete]
+#endif
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        public string GetPostBackEventReference (Control control)
        {
-               return GetPostBackEventReference (control, "");
+               return scriptManager.GetPostBackEventReference (control);
        }
 
+#if NET_2_0
+       [Obsolete]
+#endif
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        public string GetPostBackEventReference (Control control, string argument)
        {
-               RequiresPostBackScript ();
-               return String.Format ("__doPostBack('{0}','{1}')", control.UniqueID, argument);
+               return scriptManager.GetPostBackEventReference (control, argument);
        }
 
        internal void RequiresPostBackScript ()
@@ -787,8 +803,8 @@ public class Page : TemplateControl, IHttpHandler
                                        list1.Add (id);
                                }
                        }
-                       _requiresPostBack = list1;
                }
+               _requiresPostBack = list1;
        }
 
        [EditorBrowsable (EditorBrowsableState.Never)]
@@ -813,8 +829,11 @@ public class Page : TemplateControl, IHttpHandler
                        try {
                                UnloadRecursive (true);
                        } catch {}
-                       Thread.CurrentThread.CurrentCulture = culture;
-                       Thread.CurrentThread.CurrentUICulture = uiculture;
+                       if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
+                               Thread.CurrentThread.CurrentCulture = culture;
+
+                       if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
+                               Thread.CurrentThread.CurrentUICulture = uiculture;
                }
        }
        
@@ -1078,9 +1097,9 @@ public class Page : TemplateControl, IHttpHandler
                if (sState != null) {
 #if NET_2_0
                        Triplet data = (Triplet) sState;
+                       LoadPageControlState (data.Third);
                        LoadViewStateRecursive (data.First);
                        _requiresPostBack = data.Second as ArrayList;
-                       LoadPageControlState (data.Third);
 #else
                        Pair pair = (Pair) sState;
                        LoadViewStateRecursive (pair.First);
@@ -1094,6 +1113,10 @@ public class Page : TemplateControl, IHttpHandler
                if (!handleViewState)
                        return;
 
+#if NET_2_0
+               object controlState = SavePageControlState ();
+#endif
+
                object viewState = SaveViewStateRecursive ();
                object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
 
@@ -1101,7 +1124,7 @@ public class Page : TemplateControl, IHttpHandler
                Triplet triplet = new Triplet ();
                triplet.First = viewState;
                triplet.Second = reqPostback;
-               triplet.Third = SavePageControlState ();
+               triplet.Third = controlState;
 
                if (triplet.First == null && triplet.Second == null && triplet.Third == null)
                        triplet = null;
@@ -1248,108 +1271,13 @@ public class Page : TemplateControl, IHttpHandler
                }
        }
        
-       public string GetWebResourceUrl(Type type, string resourceName)
-       {
-               if (type == null)
-                       throw new ArgumentNullException ("type");
-       
-               if (resourceName == null || resourceName.Length == 0)
-                       throw new ArgumentNullException ("type");
-       
-               return System.Web.Handlers.AssemblyResourceLoader.GetResourceUrl (type, resourceName); 
-       }
-       
-       Stack dataItemCtx;
-       
-       internal void PushDataItemContext (object o)
-       {
-               if (dataItemCtx == null)
-                       dataItemCtx = new Stack ();
-               
-               dataItemCtx.Push (o);
+       public HtmlForm Form {
+               get { return _form; }
        }
        
-       internal void PopDataItemContext ()
+       internal void RegisterForm (HtmlForm form)
        {
-               if (dataItemCtx == null)
-                       throw new InvalidOperationException ();
-               
-               dataItemCtx.Pop ();
-       }
-       
-       internal object CurrentDataItem {
-               get {
-                       if (dataItemCtx == null)
-                               throw new InvalidOperationException ("No data item");
-                       
-                       return dataItemCtx.Peek ();
-               }
-       }
-       
-       protected object Eval (string expression)
-       {
-               return DataBinder.Eval (CurrentDataItem, expression);
-       }
-       
-       protected object Eval (string expression, string format)
-       {
-               return DataBinder.Eval (CurrentDataItem, expression, format);
-       }
-       
-       protected object XPath (string xpathexpression)
-       {
-               return XPathBinder.Eval (CurrentDataItem, xpathexpression);
-       }
-       
-       protected object XPath (string xpathexpression, string format)
-       {
-               return XPathBinder.Eval (CurrentDataItem, xpathexpression, format);
-       }
-       
-       protected IEnumerable XPathSelect (string xpathexpression)
-       {
-               return XPathBinder.Select (CurrentDataItem, xpathexpression);
-       }
-       
-       [EditorBrowsable (EditorBrowsableState.Advanced)]
-       public string GetCallbackEventReference (Control control, string argument, string clientCallback, string context)
-       {
-               return GetCallbackEventReference (control, argument, clientCallback, context, null);
-       }
-       
-       [EditorBrowsable (EditorBrowsableState.Advanced)]
-       public string GetCallbackEventReference (Control control, string argument, string clientCallback, string context, string clientErrorCallback)
-       {
-               if (!ClientScript.IsClientScriptIncludeRegistered (typeof(Page), "callback"))
-                       ClientScript.RegisterClientScriptInclude (typeof(Page), "callback", GetWebResourceUrl (typeof(Page), "callback.js"));
-               
-               return string.Format ("WebForm_DoCallback ('{0}', {1}, {2}, {3}, {4})", control.UniqueID, argument, clientCallback, context, clientErrorCallback);
-       }
-       
-       [EditorBrowsable (EditorBrowsableState.Advanced)]
-       public string GetPostBackEventReference (PostBackOptions options)
-       {
-               if (!ClientScript.IsClientScriptIncludeRegistered (typeof(Page), "webform")) {
-                       ClientScript.RegisterClientScriptInclude (typeof(Page), "webform", GetWebResourceUrl (typeof(Page), "webform.js"));
-               }
-               
-               if (options.ActionUrl != null)
-                       ClientScript.RegisterHiddenField (previousPageID, _context.Request.FilePath);
-               
-               if (options.ClientSubmit || options.ActionUrl != null)
-                       RequiresPostBackScript ();
-               
-               return String.Format ("{0}WebForm_DoPostback({1},{2},{3},{4},{5},{6},{7},{8})", 
-                               options.RequiresJavaScriptProtocol ? "javascript:" : "",
-                               ClientScriptManager.GetScriptLiteral (options.TargetControl.UniqueID), 
-                               ClientScriptManager.GetScriptLiteral (options.Argument),
-                               ClientScriptManager.GetScriptLiteral (options.ActionUrl),
-                               ClientScriptManager.GetScriptLiteral (options.AutoPostBack),
-                               ClientScriptManager.GetScriptLiteral (options.PerformValidation),
-                               ClientScriptManager.GetScriptLiteral (options.TrackFocus),
-                               ClientScriptManager.GetScriptLiteral (options.ClientSubmit),
-                               ClientScriptManager.GetScriptLiteral (options.ValidationGroup)
-                       );
+               _form = form;
        }
        
     [BrowsableAttribute (false)]
@@ -1362,7 +1290,7 @@ public class Page : TemplateControl, IHttpHandler
     [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
     [BrowsableAttribute (false)]
        public bool IsCallback {
-               get { return _requestValueCollection != null && _requestValueCollection [callbackArgumentID] != null; }
+               get { return _requestValueCollection != null && _requestValueCollection [CallbackArgumentID] != null; }
        }
        
     [BrowsableAttribute (false)]
@@ -1373,7 +1301,7 @@ public class Page : TemplateControl, IHttpHandler
        
        string ProcessCallbackData ()
        {
-               string callbackTarget = _requestValueCollection [callbackSourceID];
+               string callbackTarget = _requestValueCollection [CallbackSourceID];
                if (callbackTarget == null || callbackTarget.Length == 0)
                        throw new HttpException ("Callback target not provided.");
 
@@ -1381,7 +1309,7 @@ public class Page : TemplateControl, IHttpHandler
                if (target == null)
                        throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
 
-               string callbackArgument = _requestValueCollection [callbackArgumentID];
+               string callbackArgument = _requestValueCollection [CallbackArgumentID];
                return target.RaiseCallbackEvent (callbackArgument);
        }
 
@@ -1488,7 +1416,7 @@ public class Page : TemplateControl, IHttpHandler
        void LoadPreviousPageReference ()
        {
                if (_requestValueCollection != null) {
-                       string prevPage = _requestValueCollection [previousPageID];
+                       string prevPage = _requestValueCollection [PreviousPageID];
                        if (prevPage != null) {
                                previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
                                previousPage.ProcessCrossPagePostBack (_context);
@@ -1500,6 +1428,11 @@ public class Page : TemplateControl, IHttpHandler
        }
 
 
+       protected internal void AddContentTemplate (string templateName, ITemplate template)
+       {
+               Master.AddContentTemplate (templateName, template);
+       }
+               
        #endif
 }
 }