New test.
[mono.git] / mcs / class / System.Web / System.Web.UI / Page.cs
1 //
2 // System.Web.UI.Page.cs
3 //
4 // Authors:
5 //   Duncan Mak  (duncan@ximian.com)
6 //   Gonzalo Paniagua (gonzalo@ximian.com)
7 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 //
9 // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
10 // Copyright (C) 2003,2005 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Collections;
34 using System.Collections.Specialized;
35 using System.ComponentModel;
36 using System.ComponentModel.Design;
37 using System.ComponentModel.Design.Serialization;
38 using System.Globalization;
39 using System.IO;
40 using System.Security.Cryptography;
41 using System.Security.Permissions;
42 using System.Security.Principal;
43 using System.Text;
44 using System.Threading;
45 using System.Web;
46 using System.Web.Caching;
47 using System.Web.Configuration;
48 using System.Web.SessionState;
49 using System.Web.Util;
50 using System.Web.UI.HtmlControls;
51 using System.Web.UI.WebControls;
52 #if NET_2_0
53 using System.Web.UI.Adapters;
54 #endif
55
56 namespace System.Web.UI
57 {
58 // CAS
59 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
60 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
61 #if !NET_2_0
62 [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
63 #endif
64 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
65 [ToolboxItem (false)]
66 #if NET_2_0
67 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
68 #else
69 [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
70 #endif
71 public class Page : TemplateControl, IHttpHandler
72 {
73 #if NET_2_0
74         private PageLifeCycle _lifeCycle = PageLifeCycle.Unknown;
75         private bool _eventValidation = true;
76         private object [] _savedControlState;
77         private bool _doLoadPreviousPage;
78         string _focusedControlID;
79 #endif
80         private bool _viewState = true;
81         private bool _viewStateMac;
82         private string _errorPage;
83         private bool is_validated;
84         private bool _smartNavigation;
85         private int _transactionMode;
86         private HttpContext _context;
87         private ValidatorCollection _validators;
88         private bool renderingForm;
89         private object _savedViewState;
90         private ArrayList _requiresPostBack;
91         private ArrayList _requiresPostBackCopy;
92         private ArrayList requiresPostDataChanged;
93         private IPostBackEventHandler requiresRaiseEvent;
94         private NameValueCollection secondPostData;
95         private bool requiresPostBackScript;
96         private bool postBackScriptRendered;
97         bool handleViewState;
98         string viewStateUserKey;
99         NameValueCollection _requestValueCollection;
100         string clientTarget;
101         ClientScriptManager scriptManager;
102         bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
103
104         [EditorBrowsable (EditorBrowsableState.Never)]
105 #if NET_2_0
106         public
107 #else
108         protected
109 #endif
110         const string postEventArgumentID = "__EVENTARGUMENT";
111
112         [EditorBrowsable (EditorBrowsableState.Never)]
113 #if NET_2_0
114         public
115 #else
116         protected
117 #endif
118         const string postEventSourceID = "__EVENTTARGET";
119
120 #if NET_2_0
121         const string ScrollPositionXID = "__SCROLLPOSITIONX";
122         const string ScrollPositionYID = "__SCROLLPOSITIONY";
123 #endif
124
125 #if NET_2_0
126         internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
127         internal const string CallbackSourceID = "__CALLBACKTARGET";
128         internal const string PreviousPageID = "__PREVIOUSPAGE";
129         
130         HtmlHead htmlHeader;
131         
132         MasterPage masterPage;
133         string masterPageFile;
134         
135         Page previousPage;
136         bool isCrossPagePostBack;
137         bool isPostBack;
138         bool isCallback;
139         ArrayList requireStateControls;
140         Hashtable _validatorsByGroup;
141         HtmlForm _form;
142
143         string _title;
144         string _theme;
145         string _styleSheetTheme;
146         Hashtable items;
147
148         bool _maintainScrollPositionOnPostBack;
149 #endif
150
151         #region Constructor
152         public Page ()
153         {
154                 scriptManager = new ClientScriptManager (this);
155                 Page = this;
156                 ID = "__Page";
157         }
158
159         #endregion              
160
161         #region Properties
162
163         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
164         [Browsable (false)]
165         public HttpApplicationState Application
166         {
167                 get {
168                         if (_context == null)
169                                 return null;
170                         return _context.Application;
171                 }
172         }
173
174         [EditorBrowsable (EditorBrowsableState.Never)]
175         protected bool AspCompatMode
176         {
177 #if NET_2_0
178                 get { return false; }
179 #endif
180                 set { throw new NotImplementedException (); }
181         }
182
183         [EditorBrowsable (EditorBrowsableState.Never)]
184 #if NET_2_0
185         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
186         [BrowsableAttribute (false)]
187         public bool Buffer
188         {
189                 get { return Response.BufferOutput; }
190                 set { Response.BufferOutput = value; }
191         }
192 #else
193         protected bool Buffer
194         {
195                 set { Response.BufferOutput = value; }
196         }
197 #endif
198
199         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
200         [Browsable (false)]
201         public Cache Cache
202         {
203                 get {
204                         if (_context == null)
205                                 throw new HttpException ("No cache available without a context.");
206                         return _context.Cache;
207                 }
208         }
209
210 #if NET_2_0
211         [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
212 #endif
213         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
214         [Browsable (false), DefaultValue ("")]
215         [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
216         public string ClientTarget
217         {
218                 get { return (clientTarget == null) ? "" : clientTarget; }
219                 set {
220                         clientTarget = value;
221                         if (value == "")
222                                 clientTarget = null;
223                 }
224         }
225
226         [EditorBrowsable (EditorBrowsableState.Never)]
227 #if NET_2_0
228         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
229         [BrowsableAttribute (false)]
230         public int CodePage
231         {
232                 get { return Response.ContentEncoding.CodePage; }
233                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
234         }
235 #else
236         protected int CodePage
237         {
238                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
239         }
240 #endif
241
242         [EditorBrowsable (EditorBrowsableState.Never)]
243 #if NET_2_0
244         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
245         [BrowsableAttribute (false)]
246         public string ContentType
247         {
248                 get { return Response.ContentType; }
249                 set { Response.ContentType = value; }
250         }
251 #else
252         protected string ContentType
253         {
254                 set { Response.ContentType = value; }
255         }
256 #endif
257
258         protected override HttpContext Context
259         {
260                 get {
261                         if (_context == null)
262                                 return HttpContext.Current;
263
264                         return _context;
265                 }
266         }
267
268 #if NET_2_0
269         [EditorBrowsable (EditorBrowsableState.Advanced)]
270         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
271         [BrowsableAttribute (false)]
272         public string Culture
273         {
274                 get { return Thread.CurrentThread.CurrentCulture.Name; }
275                 set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
276         }
277 #else
278         [EditorBrowsable (EditorBrowsableState.Never)]
279         protected string Culture
280         {
281                 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
282         }
283 #endif
284
285 #if NET_2_0
286         public virtual bool EnableEventValidation {
287                 get { return _eventValidation; }
288                 set {
289                         if (_lifeCycle > PageLifeCycle.Init)
290                                 throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
291                         _eventValidation = value;
292                 }
293         }
294
295         internal PageLifeCycle LifeCycle {
296                 get { return _lifeCycle; }
297         }
298 #endif
299
300         [Browsable (false)]
301         public override bool EnableViewState
302         {
303                 get { return _viewState; }
304                 set { _viewState = value; }
305         }
306
307 #if NET_2_0
308         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
309         [BrowsableAttribute (false)]
310 #endif
311         [EditorBrowsable (EditorBrowsableState.Never)]
312 #if NET_2_0
313         public
314 #else
315         protected
316 #endif
317         bool EnableViewStateMac
318         {
319                 get { return _viewStateMac; }
320                 set { _viewStateMac = value; }
321         }
322
323         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
324         [Browsable (false), DefaultValue ("")]
325         [WebSysDescription ("The URL of a page used for error redirection.")]
326         public string ErrorPage
327         {
328                 get { return _errorPage; }
329                 set {
330                         _errorPage = value;
331                         if (_context != null)
332                                 _context.ErrorPage = value;
333                 }
334         }
335
336 #if NET_2_0
337         [Obsolete]
338 #endif
339         [EditorBrowsable (EditorBrowsableState.Never)]
340         protected ArrayList FileDependencies
341         {
342                 set {
343                         if (Response != null)
344                                 Response.AddFileDependencies (value);
345                 }
346         }
347
348         [Browsable (false)]
349 #if NET_2_0
350         [EditorBrowsable (EditorBrowsableState.Never)]
351 #endif
352         public override string ID
353         {
354                 get { return base.ID; }
355                 set { base.ID = value; }
356         }
357
358         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
359         [Browsable (false)]
360         public bool IsPostBack
361         {
362                 get {
363 #if NET_2_0
364                         return isPostBack;
365 #else
366                         return _requestValueCollection != null;
367 #endif
368                 }
369         }
370
371         [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
372         public bool IsReusable {
373                 get { return false; }
374         }
375
376         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
377         [Browsable (false)]
378         public bool IsValid {
379                 get {
380                         if (!is_validated)
381                                 throw new HttpException (Locale.GetText ("Page hasn't been validated."));
382
383 #if NET_2_0
384                         foreach (IValidator val in Validators)
385                                 if (!val.IsValid)
386                                         return false;
387                         return true;
388 #else
389                         return ValidateCollection (_validators);
390 #endif
391                 }
392         }
393 #if NET_2_0
394         public IDictionary Items {
395                 get {
396                         if (items == null)
397                                 items = new Hashtable ();
398                         return items;
399                 }
400         }
401 #endif
402
403         [EditorBrowsable (EditorBrowsableState.Never)]
404 #if NET_2_0
405         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
406         [BrowsableAttribute (false)]
407         public int LCID {
408                 get { return Thread.CurrentThread.CurrentCulture.LCID; }
409                 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
410         }
411 #else
412         protected int LCID {
413                 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
414         }
415 #endif
416
417 #if NET_2_0
418         [Browsable (false)]
419         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
420         public bool MaintainScrollPositionOnPostBack {
421                 get { return _maintainScrollPositionOnPostBack; }
422                 set { _maintainScrollPositionOnPostBack = value; }
423         }
424 #endif
425
426 #if NET_2_0
427         public PageAdapter PageAdapter {
428                 get {
429                         return (PageAdapter)Adapter;
430                 }
431         }
432 #endif
433
434         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
435         [Browsable (false)]
436         public HttpRequest Request
437         {
438                 get {
439                         if (_context != null)
440                                 return _context.Request;
441
442                         throw new HttpException("Request is not available without context");
443                 }
444         }
445
446         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
447         [Browsable (false)]
448         public HttpResponse Response
449         {
450                 get {
451                         if (_context != null)
452                                 return _context.Response;
453
454                         throw new HttpException ("Response is not available without context");
455                 }
456         }
457
458         [EditorBrowsable (EditorBrowsableState.Never)]
459 #if NET_2_0
460         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
461         [BrowsableAttribute (false)]
462         public string ResponseEncoding
463         {
464                 get { return Response.ContentEncoding.WebName; }
465                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
466         }
467 #else
468         protected string ResponseEncoding
469         {
470                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
471         }
472 #endif
473
474         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
475         [Browsable (false)]
476         public HttpServerUtility Server
477         {
478                 get {
479                         return Context.Server;
480                 }
481         }
482
483         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
484         [Browsable (false)]
485         public virtual HttpSessionState Session
486         {
487                 get {
488                         if (_context == null)
489                                 _context = HttpContext.Current;
490
491                         if (_context == null)
492                                 throw new HttpException ("Session is not available without context");
493
494                         if (_context.Session == null)
495                                 throw new HttpException ("Session state can only be used " +
496                                                 "when enableSessionState is set to true, either " +
497                                                 "in a configuration file or in the Page directive.");
498
499                         return _context.Session;
500                 }
501         }
502
503 #if NET_2_0
504         [FilterableAttribute (false)]
505         [Obsolete]
506 #endif
507         [Browsable (false)]
508         public bool SmartNavigation
509         {
510                 get { return _smartNavigation; }
511                 set { _smartNavigation = value; }
512         }
513
514 #if NET_2_0
515         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
516         [Filterable (false)]
517         [Browsable (false)]
518         public virtual string StyleSheetTheme {
519                 get { return _styleSheetTheme; }
520                 set { _styleSheetTheme = value; }
521         }
522
523         [Browsable (false)]
524         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
525         public virtual string Theme {
526                 get { return _theme; }
527                 set { _theme = value; }
528         }
529
530         void InitializeStyleSheet ()
531         {
532                 if (_styleSheetTheme == null) {
533                         PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
534                         if (ps != null)
535                                 _styleSheetTheme = ps.StyleSheetTheme;
536                 }
537                 if (_styleSheetTheme != null && _styleSheetTheme != "")
538                         _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("~/App_Themes/" + _styleSheetTheme + "/", _context);
539         }
540
541         void InitializeTheme ()
542         {
543                 if (_theme == null) {
544                         PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
545                         if (ps != null)
546                                 _theme = ps.Theme;
547                 }
548                 if (_theme != null && _theme != "") {
549                         _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("~/App_Themes/" + _theme + "/", _context);
550                 }
551         }
552
553 #endif
554
555 #if NET_2_0
556         [Localizable (true)] 
557         [Bindable (true)] 
558         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
559         public string Title {
560                 get {
561                         if (_title == null)
562                                 return htmlHeader.Title;
563                         return _title;
564                 }
565                 set {
566                         if (htmlHeader != null)
567                                 htmlHeader.Title = value;
568                         else
569                                 _title = value;
570                 }
571         }
572 #endif
573
574         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
575         [Browsable (false)]
576         public TraceContext Trace
577         {
578                 get { return Context.Trace; }
579         }
580
581         [EditorBrowsable (EditorBrowsableState.Never)]
582 #if NET_2_0
583         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
584         [BrowsableAttribute (false)]
585         public bool TraceEnabled
586         {
587                 get { return Trace.IsEnabled; }
588                 set { Trace.IsEnabled = value; }
589         }
590 #else
591         protected bool TraceEnabled
592         {
593                 set { Trace.IsEnabled = value; }
594         }
595 #endif
596
597         [EditorBrowsable (EditorBrowsableState.Never)]
598 #if NET_2_0
599         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
600         [BrowsableAttribute (false)]
601         public TraceMode TraceModeValue
602         {
603                 get { return Trace.TraceMode; }
604                 set { Trace.TraceMode = value; }
605         }
606 #else
607         protected TraceMode TraceModeValue
608         {
609                 set { Trace.TraceMode = value; }
610         }
611 #endif
612
613         [EditorBrowsable (EditorBrowsableState.Never)]
614         protected int TransactionMode
615         {
616 #if NET_2_0
617                 get { return _transactionMode; }
618 #endif
619                 set { _transactionMode = value; }
620         }
621
622 #if NET_2_0
623         [EditorBrowsable (EditorBrowsableState.Advanced)]
624         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
625         [BrowsableAttribute (false)]
626         public string UICulture
627         {
628                 get { return Thread.CurrentThread.CurrentUICulture.Name; }
629                 set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
630         }
631 #else
632         [EditorBrowsable (EditorBrowsableState.Never)]
633         protected string UICulture
634         {
635                 set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
636         }
637 #endif
638
639         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
640         [Browsable (false)]
641         public IPrincipal User
642         {
643                 get { return Context.User; }
644         }
645
646         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
647         [Browsable (false)]
648         public ValidatorCollection Validators
649         {
650                 get { 
651                         if (_validators == null)
652                                 _validators = new ValidatorCollection ();
653                         return _validators;
654                 }
655         }
656
657         [MonoTODO ("Use this when encrypting/decrypting ViewState")]
658         [Browsable (false)]
659         public string ViewStateUserKey {
660                 get { return viewStateUserKey; }
661                 set { viewStateUserKey = value; }
662         }
663
664         [Browsable (false)]
665         public override bool Visible
666         {
667                 get { return base.Visible; }
668                 set { base.Visible = value; }
669         }
670
671         #endregion
672
673         #region Methods
674
675 #if NET_2_0
676         CultureInfo GetPageCulture (string culture, CultureInfo deflt)
677         {
678                 if (culture == null)
679                         return deflt;
680                 CultureInfo ret = null;
681                 if (culture.StartsWith ("auto")) {
682                         string[] languages = Request.UserLanguages;
683                         try {
684                                 if (languages != null && languages.Length > 0)
685                                         ret = new CultureInfo (languages[0]);
686                         } catch {
687                         }
688                         
689                         if (ret == null)
690                                 ret = deflt;
691                 } else
692                         ret = new CultureInfo (culture);
693
694                 return ret;
695         }
696 #endif
697
698         [EditorBrowsable (EditorBrowsableState.Never)]
699         protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
700                                                              AsyncCallback cb, 
701                                                              object extraData)
702         {
703                 throw new NotImplementedException ();
704         }
705
706         [EditorBrowsable (EditorBrowsableState.Never)]
707         protected void AspCompatEndProcessRequest (IAsyncResult result)
708         {
709                 throw new NotImplementedException ();
710         }
711         
712         [EditorBrowsable (EditorBrowsableState.Advanced)]
713         protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
714         {
715                 return new HtmlTextWriter (tw);
716         }
717
718         [EditorBrowsable (EditorBrowsableState.Never)]
719         public void DesignerInitialize ()
720         {
721                 InitRecursive (null);
722         }
723
724         [EditorBrowsable (EditorBrowsableState.Advanced)]
725         protected virtual NameValueCollection DeterminePostBackMode ()
726         {
727                 if (_context == null)
728                         return null;
729
730                 HttpRequest req = _context.Request;
731                 if (req == null)
732                         return null;
733
734                 NameValueCollection coll = null;
735                 if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
736                         coll =  req.Form;
737                         WebROCollection c = (WebROCollection) coll;
738                         allow_load = !c.GotID;
739                         if (allow_load) {
740                                 c.ID = GetTypeHashCode ();
741                         } else {
742                                 allow_load = (c.ID == GetTypeHashCode ());
743                         }
744                 } else  {
745                         coll = req.QueryString;
746                 }
747
748                 if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
749                         return null;
750
751                 return coll;
752         }
753
754 #if NET_2_0
755         public override Control FindControl (string id) {
756                 if (id == ID)
757                         return this;
758                 else
759                         return base.FindControl (id);
760         }
761 #endif
762
763 #if NET_2_0
764         [Obsolete]
765 #endif
766         [EditorBrowsable (EditorBrowsableState.Advanced)]
767         public string GetPostBackClientEvent (Control control, string argument)
768         {
769                 return scriptManager.GetPostBackEventReference (control, argument);
770         }
771
772 #if NET_2_0
773         [Obsolete]
774 #endif
775         [EditorBrowsable (EditorBrowsableState.Advanced)]
776         public string GetPostBackClientHyperlink (Control control, string argument)
777         {
778                 return scriptManager.GetPostBackClientHyperlink (control, argument);
779         }
780
781 #if NET_2_0
782         [Obsolete]
783 #endif
784         [EditorBrowsable (EditorBrowsableState.Advanced)]
785         public string GetPostBackEventReference (Control control)
786         {
787                 return scriptManager.GetPostBackEventReference (control, "");
788         }
789
790 #if NET_2_0
791         [Obsolete]
792 #endif
793         [EditorBrowsable (EditorBrowsableState.Advanced)]
794         public string GetPostBackEventReference (Control control, string argument)
795         {
796                 return scriptManager.GetPostBackEventReference (control, argument);
797         }
798
799         internal void RequiresPostBackScript ()
800         {
801                 requiresPostBackScript = true;
802         }
803
804         [EditorBrowsable (EditorBrowsableState.Never)]
805         public virtual int GetTypeHashCode ()
806         {
807                 return 0;
808         }
809
810 #if NET_2_0
811     [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
812     protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
813     {
814         if (cacheSettings.Enabled)
815             InitOutputCache(cacheSettings.Duration,
816                 cacheSettings.VaryByHeader,
817                 cacheSettings.VaryByCustom,
818                 cacheSettings.Location,
819                 cacheSettings.VaryByParam);
820     }
821 #endif
822
823         [EditorBrowsable (EditorBrowsableState.Never)]
824         protected virtual void InitOutputCache (int duration,
825                                                 string varyByHeader,
826                                                 string varyByCustom,
827                                                 OutputCacheLocation location,
828                                                 string varyByParam)
829         {
830                 HttpCachePolicy cache = _context.Response.Cache;
831                 bool set_vary = false;
832
833                 switch (location) {
834                 case OutputCacheLocation.Any:
835                         cache.SetCacheability (HttpCacheability.Public);
836                         cache.SetMaxAge (new TimeSpan (0, 0, duration));                
837                         cache.SetLastModified (_context.Timestamp);
838                         set_vary = true;
839                         break;
840                 case OutputCacheLocation.Client:
841                         cache.SetCacheability (HttpCacheability.Private);
842                         cache.SetMaxAge (new TimeSpan (0, 0, duration));                
843                         cache.SetLastModified (_context.Timestamp);
844                         break;
845                 case OutputCacheLocation.Downstream:
846                         cache.SetCacheability (HttpCacheability.Public);
847                         cache.SetMaxAge (new TimeSpan (0, 0, duration));                
848                         cache.SetLastModified (_context.Timestamp);
849                         break;
850                 case OutputCacheLocation.Server:                        
851                         cache.SetCacheability (HttpCacheability.Server);
852                         set_vary = true;
853                         break;
854                 case OutputCacheLocation.None:
855                         break;
856                 }
857
858                 if (set_vary) {
859                         if (varyByCustom != null)
860                                 cache.SetVaryByCustom (varyByCustom);
861
862                         if (varyByParam != null && varyByParam.Length > 0) {
863                                 string[] prms = varyByParam.Split (';');
864                                 foreach (string p in prms)
865                                         cache.VaryByParams [p.Trim ()] = true;
866                                 cache.VaryByParams.IgnoreParams = false;
867                         } else {
868                                 cache.VaryByParams.IgnoreParams = true;
869                         }
870                         
871                         if (varyByHeader != null && varyByHeader.Length > 0) {
872                                 string[] hdrs = varyByHeader.Split (';');
873                                 foreach (string h in hdrs)
874                                         cache.VaryByHeaders [h.Trim ()] = true;
875                         }
876                 }
877                         
878                 cache.Duration = duration;
879                 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
880         }
881
882 #if NET_2_0
883         [Obsolete]
884 #else
885         [EditorBrowsable (EditorBrowsableState.Advanced)]
886 #endif
887         public bool IsClientScriptBlockRegistered (string key)
888         {
889                 return scriptManager.IsClientScriptBlockRegistered (key);
890         }
891
892 #if NET_2_0
893         [Obsolete]
894 #else
895         [EditorBrowsable (EditorBrowsableState.Advanced)]
896 #endif
897         public bool IsStartupScriptRegistered (string key)
898         {
899                 return scriptManager.IsStartupScriptRegistered (key);
900         }
901
902         public string MapPath (string virtualPath)
903         {
904                 return Request.MapPath (virtualPath);
905         }
906
907 #if NET_2_0
908         protected internal override void Render (HtmlTextWriter writer) {
909                 if (MaintainScrollPositionOnPostBack) {
910                         RequiresPostBackScript ();
911
912                         string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
913
914                         ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
915
916                         ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
917                         ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
918                         
919                         StringBuilder script = new StringBuilder ();
920                         script.AppendLine ("<script type=\"text/javascript\">");
921                         script.AppendLine ("<!--");
922                         script.AppendLine ("theForm.oldSubmit = theForm.submit");
923                         script.AppendLine ("theForm.submit = WebForm_SaveScrollPositionSubmit");
924                         script.AppendLine ("theForm.oldOnSubmit = theForm.onsubmit");
925                         script.AppendLine ("theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit");
926                         if (IsPostBack) {
927                                 script.AppendLine ("theForm.oldOnLoad = window.onload");
928                                 script.AppendLine ("window.onload = WebForm_RestoreScrollPosition");
929                         }
930                         script.AppendLine ("// -->");
931                         script.AppendLine ("</script>");
932                         
933                         ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
934                 }
935                 base.Render (writer);
936         }
937 #endif
938
939         private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
940         {
941                 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
942                 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
943                 writer.WriteLine ();
944                 writer.WriteLine ("<script language=\"javascript\">");
945                 writer.WriteLine ("<!--");
946
947                 writer.WriteLine ("\tvar theForm;\n\tif (document.getElementById) {{ theForm = document.getElementById ('{0}'); }}", formUniqueID);
948                 writer.WriteLine ("\telse {{ theForm = document.{0}; }}", formUniqueID);
949                 writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
950                 writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
951                 writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
952                 writer.WriteLine ("\t\ttheForm.submit();");
953                 writer.WriteLine ("\t}");
954                 writer.WriteLine ("// -->");
955                 writer.WriteLine ("</script>");
956         }
957
958         internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
959         {
960                 if (renderingForm)
961                         throw new HttpException ("Only 1 HtmlForm is allowed per page.");
962
963                 renderingForm = true;
964                 writer.WriteLine ();
965                 scriptManager.WriteHiddenFields (writer);
966                 if (requiresPostBackScript) {
967                         RenderPostBackScript (writer, formUniqueID);
968                         postBackScriptRendered = true;
969                 }
970
971                 if (handleViewState) {
972                         string vs = GetViewStateString ();
973                         writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
974                         writer.WriteLine ("value=\"{0}\" />", vs);
975                 }
976
977                 scriptManager.WriteClientScriptBlocks (writer);
978         }
979
980         internal LosFormatter GetFormatter ()
981         {
982 #if NET_2_0
983                 PagesSection config = (PagesSection) WebConfigurationManager.GetSection ("system.web/pages");
984 #else
985                 PagesConfiguration config = PagesConfiguration.GetInstance (_context);
986 #endif
987                 byte [] vkey = null;
988                 if (config.EnableViewStateMac) {
989 #if NET_2_0
990                         MachineKeySection mconfig = (MachineKeySection) WebConfigurationManager.GetSection ("system.web/machineKey");
991                         vkey = mconfig.ValidationKeyBytes;
992 #else
993                         MachineKeyConfig mconfig = HttpContext.GetAppConfig ("system.web/machineKey") as MachineKeyConfig;
994                         vkey = mconfig.ValidationKey;
995 #endif
996                 }
997
998                 return new LosFormatter (config.EnableViewStateMac, vkey);
999         }
1000
1001         string GetViewStateString ()
1002         {
1003                 if (_savedViewState == null)
1004                         return null;
1005
1006                 LosFormatter fmt = GetFormatter ();
1007                 return fmt.SerializeToBase64 (_savedViewState);
1008         }
1009
1010         internal object GetSavedViewState ()
1011         {
1012                 return _savedViewState;
1013         }
1014
1015         internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1016         {
1017                 scriptManager.WriteArrayDeclares (writer);
1018
1019                 if (!postBackScriptRendered && requiresPostBackScript)
1020                         RenderPostBackScript (writer, formUniqueID);
1021                 
1022 #if NET_2_0
1023                 scriptManager.SaveEventValidationState ();
1024                 scriptManager.WriteExpandoAttributes (writer);
1025 #endif
1026                 scriptManager.WriteHiddenFields (writer);
1027                 scriptManager.WriteClientScriptIncludes (writer);
1028                 scriptManager.WriteStartupScriptBlocks (writer);
1029                 renderingForm = false;
1030                 postBackScriptRendered = false;
1031         }
1032
1033         private void ProcessPostData (NameValueCollection data, bool second)
1034         {
1035                 if (data == null)
1036                         return;
1037
1038                 if (_requiresPostBackCopy == null && _requiresPostBack != null)
1039                         _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
1040
1041                 Hashtable used = new Hashtable ();
1042                 foreach (string id in data.AllKeys){
1043                         if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
1044                                 continue;
1045
1046                         string real_id = id;
1047                         int dot = real_id.IndexOf ('.');
1048                         if (dot >= 1)
1049                                 real_id = real_id.Substring (0, dot);
1050                         
1051                         if (real_id == null || used.ContainsKey (real_id))
1052                                 continue;
1053
1054                         used.Add (real_id, real_id);
1055
1056                         Control ctrl = FindControl (real_id);
1057                         if (ctrl != null){
1058                                 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1059                                 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1060
1061                                 if (pbdh == null) {
1062                                         if (pbeh != null)
1063                                                 RegisterRequiresRaiseEvent (pbeh);
1064                                         continue;
1065                                 }
1066                 
1067                                 if (pbdh.LoadPostData (real_id, data) == true) {
1068                                         if (requiresPostDataChanged == null)
1069                                                 requiresPostDataChanged = new ArrayList ();
1070                                         requiresPostDataChanged.Add (pbdh);
1071                                         if (_requiresPostBackCopy != null)
1072                                                 _requiresPostBackCopy.Remove (ctrl.UniqueID);
1073                                 }
1074                         } else if (!second) {
1075                                 if (secondPostData == null)
1076                                         secondPostData = new NameValueCollection ();
1077                                 secondPostData.Add (real_id, data [id]);
1078                         }
1079                 }
1080
1081                 ArrayList list1 = null;
1082                 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1083                         string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1084                         foreach (string id in handlers) {
1085                                 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
1086                                 if (pbdh != null) {                     
1087                                         _requiresPostBackCopy.Remove (id);
1088                                         if (pbdh.LoadPostData (id, data)) {
1089                                                 if (requiresPostDataChanged == null)
1090                                                         requiresPostDataChanged = new ArrayList ();
1091         
1092                                                 requiresPostDataChanged.Add (pbdh);
1093                                         }
1094                                 } else if (second) {
1095                                         if (list1 == null)
1096                                                 list1 = new ArrayList ();
1097                                         list1.Add (id);
1098                                 }
1099                         }
1100                 }
1101                 _requiresPostBack = list1;
1102         }
1103
1104         [EditorBrowsable (EditorBrowsableState.Never)]
1105 #if NET_2_0 || TARGET_JVM
1106         public virtual void ProcessRequest (HttpContext context)
1107 #else
1108         public void ProcessRequest (HttpContext context)
1109 #endif
1110         {
1111 #if NET_2_0
1112                 _lifeCycle = PageLifeCycle.Unknown;
1113 #endif
1114                 _context = context;
1115                 if (clientTarget != null)
1116                         Request.ClientTarget = clientTarget;
1117
1118                 WireupAutomaticEvents ();
1119                 //-- Control execution lifecycle in the docs
1120
1121                 // Save culture information because it can be modified in FrameworkInitialize()
1122                 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
1123                 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
1124                 FrameworkInitialize ();
1125                 context.ErrorPage = _errorPage;
1126
1127                 try {
1128                         InternalProcessRequest ();
1129                 } catch (ThreadAbortException) {
1130                         // Do nothing, just ignore it by now.
1131                 } catch (Exception e) {
1132                         context.AddError (e); // OnError might access LastError
1133                         OnError (EventArgs.Empty);
1134                         context.ClearError (e);
1135                         // We want to remove that error, as we're rethrowing to stop
1136                         // further processing.
1137                         Trace.Warn ("Unhandled Exception", e.ToString (), e);
1138                         throw;
1139                 } finally {
1140                         try {
1141 #if NET_2_0
1142                                 _lifeCycle = PageLifeCycle.Unload;
1143 #endif
1144                                 RenderTrace ();
1145                                 UnloadRecursive (true);
1146 #if NET_2_0
1147                                 _lifeCycle = PageLifeCycle.End;
1148 #endif
1149                         } catch {}
1150                         if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
1151                                 Thread.CurrentThread.CurrentCulture = culture;
1152
1153                         if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
1154                                 Thread.CurrentThread.CurrentUICulture = uiculture;
1155                 }
1156         }
1157         
1158 #if NET_2_0
1159         internal void ProcessCrossPagePostBack (HttpContext context)
1160         {
1161                 isCrossPagePostBack = true;
1162                 ProcessRequest (context);
1163         }
1164 #endif
1165
1166         void InternalProcessRequest ()
1167         {
1168                 _requestValueCollection = this.DeterminePostBackMode();
1169
1170 #if NET_2_0
1171                 _lifeCycle = PageLifeCycle.Start;
1172                 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1173                 if (_requestValueCollection != null) {
1174                         if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1175                                 _doLoadPreviousPage = true;
1176                         }
1177                         else {
1178                                 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1179                                 isPostBack = !isCallback;
1180                         }
1181                 }
1182                 
1183                 // if request was transfered from other page - track Prev. Page
1184                 previousPage = _context.LastPage;
1185                 _context.LastPage = this;
1186
1187                 InitializeCulture ();
1188                 _lifeCycle = PageLifeCycle.PreInit;
1189                 OnPreInit (EventArgs.Empty);
1190
1191                 InitializeTheme ();
1192                 ApplyMasterPage ();
1193                 _lifeCycle = PageLifeCycle.Init;
1194 #endif
1195                 Trace.Write ("aspx.page", "Begin Init");
1196                 InitRecursive (null);
1197                 Trace.Write ("aspx.page", "End Init");
1198
1199 #if NET_2_0
1200                 _lifeCycle = PageLifeCycle.InitComplete;
1201                 OnInitComplete (EventArgs.Empty);
1202 #endif
1203                         
1204                 renderingForm = false;  
1205 #if NET_2_0
1206                 if (IsPostBack || IsCallback) {
1207                         _lifeCycle = PageLifeCycle.PreLoad;
1208                         if (_requestValueCollection != null)
1209                                 scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
1210 #else
1211                 if (IsPostBack) {
1212 #endif
1213                         Trace.Write ("aspx.page", "Begin LoadViewState");
1214                         LoadPageViewState ();
1215                         Trace.Write ("aspx.page", "End LoadViewState");
1216                         Trace.Write ("aspx.page", "Begin ProcessPostData");
1217                         ProcessPostData (_requestValueCollection, false);
1218                         Trace.Write ("aspx.page", "End ProcessPostData");
1219                 }
1220
1221 #if NET_2_0
1222                 OnPreLoad (EventArgs.Empty);
1223                 _lifeCycle = PageLifeCycle.Load;
1224 #endif
1225
1226                 LoadRecursive ();
1227 #if NET_2_0
1228                 if (IsPostBack || IsCallback) {
1229                         _lifeCycle = PageLifeCycle.ControlEvents;
1230 #else
1231                 if (IsPostBack) {
1232 #endif
1233                         Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1234                         ProcessPostData (secondPostData, true);
1235                         Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1236                         Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1237                         RaiseChangedEvents ();
1238                         Trace.Write ("aspx.page", "End Raise ChangedEvents");
1239                         Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1240                         RaisePostBackEvents ();
1241                         Trace.Write ("aspx.page", "End Raise PostBackEvent");
1242                 }
1243                 
1244 #if NET_2_0
1245                 _lifeCycle = PageLifeCycle.LoadComplete;
1246                 OnLoadComplete (EventArgs.Empty);
1247
1248                 if (IsCrossPagePostBack)
1249                         return;
1250
1251                 if (IsCallback) {
1252                         string result = ProcessCallbackData ();
1253                         HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
1254                         callbackOutput.Write (result);
1255                         callbackOutput.Flush ();
1256                         return;
1257                 }
1258
1259                 _lifeCycle = PageLifeCycle.PreRender;
1260 #endif
1261                 
1262                 Trace.Write ("aspx.page", "Begin PreRender");
1263                 PreRenderRecursiveInternal ();
1264                 Trace.Write ("aspx.page", "End PreRender");
1265                 
1266 #if NET_2_0
1267                 _lifeCycle = PageLifeCycle.PreRenderComplete;
1268                 OnPreRenderComplete (EventArgs.Empty);
1269 #endif
1270
1271                 Trace.Write ("aspx.page", "Begin SaveViewState");
1272                 SavePageViewState ();
1273                 Trace.Write ("aspx.page", "End SaveViewState");
1274                 
1275 #if NET_2_0
1276                 _lifeCycle = PageLifeCycle.SaveStateComplete;
1277                 OnSaveStateComplete (EventArgs.Empty);
1278                 _lifeCycle = PageLifeCycle.Render;
1279 #endif
1280                 
1281                 //--
1282                 Trace.Write ("aspx.page", "Begin Render");
1283                 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1284                 RenderControl (output);
1285                 Trace.Write ("aspx.page", "End Render");
1286         }
1287
1288         private void RenderTrace ()
1289         {
1290                 TraceManager traceManager = HttpRuntime.TraceManager;
1291
1292                 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1293                         return;
1294                 
1295                 Trace.SaveData ();
1296
1297                 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput) 
1298                         return;
1299
1300                 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1301                         HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1302                         Trace.Render (output);
1303                 }
1304         }
1305         
1306 #if NET_2_0
1307         bool CheckForValidationSupport (Control targetControl)
1308         {
1309                 if (targetControl == null)
1310                         return false;
1311                 Type type = targetControl.GetType ();
1312                 object[] attributes = type.GetCustomAttributes (true);
1313                 foreach (object attr in attributes)
1314                         if (attr is SupportsEventValidationAttribute)
1315                                 return true;
1316                 return false;
1317         }
1318 #endif
1319         
1320         void RaisePostBackEvents ()
1321         {
1322 #if NET_2_0
1323                 Control targetControl;
1324 #endif
1325                 if (requiresRaiseEvent != null) {
1326 #if NET_2_0
1327                         targetControl = requiresRaiseEvent as Control;
1328                         if (targetControl != null && CheckForValidationSupport (targetControl))
1329                                 scriptManager.ValidateEvent (targetControl.UniqueID, null);
1330 #endif
1331                         RaisePostBackEvent (requiresRaiseEvent, null);
1332                         return;
1333                 }
1334
1335                 NameValueCollection postdata = _requestValueCollection;
1336                 if (postdata == null)
1337                         return;
1338
1339                 string eventTarget = postdata [postEventSourceID];
1340                 if (eventTarget == null || eventTarget.Length == 0) {
1341                         Validate ();
1342                         return;
1343                 }
1344
1345 #if NET_2_0
1346                 targetControl = FindControl (eventTarget);
1347                 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1348 #else
1349                 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
1350 #endif
1351                         
1352                 if (target == null)
1353                         return;
1354
1355                 string eventArgument = postdata [postEventArgumentID];
1356 #if NET_2_0
1357                 if (CheckForValidationSupport (targetControl))
1358                         scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
1359 #endif
1360                 RaisePostBackEvent (target, eventArgument);
1361         }
1362
1363         internal void RaiseChangedEvents ()
1364         {
1365                 if (requiresPostDataChanged == null)
1366                         return;
1367
1368                 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1369                         ipdh.RaisePostDataChangedEvent ();
1370
1371                 requiresPostDataChanged = null;
1372         }
1373
1374         [EditorBrowsable (EditorBrowsableState.Advanced)]
1375         protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1376         {
1377                 sourceControl.RaisePostBackEvent (eventArgument);
1378         }
1379         
1380 #if NET_2_0
1381         [Obsolete]
1382 #endif
1383         [EditorBrowsable (EditorBrowsableState.Advanced)]
1384         public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1385         {
1386                 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1387         }
1388
1389 #if NET_2_0
1390         [Obsolete]
1391 #endif
1392         [EditorBrowsable (EditorBrowsableState.Advanced)]
1393         public virtual void RegisterClientScriptBlock (string key, string script)
1394         {
1395                 scriptManager.RegisterClientScriptBlock (key, script);
1396         }
1397
1398 #if NET_2_0
1399         [Obsolete]
1400 #endif
1401         [EditorBrowsable (EditorBrowsableState.Advanced)]
1402         public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1403         {
1404                 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1405         }
1406
1407         [MonoTODO("Not implemented, Used in HtmlForm")]
1408         internal void RegisterClientScriptFile (string a, string b, string c)
1409         {
1410                 throw new NotImplementedException ();
1411         }
1412
1413 #if NET_2_0
1414         [Obsolete]
1415 #endif
1416         [EditorBrowsable (EditorBrowsableState.Advanced)]
1417         public void RegisterOnSubmitStatement (string key, string script)
1418         {
1419                 scriptManager.RegisterOnSubmitStatement (key, script);
1420         }
1421
1422         internal string GetSubmitStatements ()
1423         {
1424                 return scriptManager.WriteSubmitStatements ();
1425         }
1426
1427         [EditorBrowsable (EditorBrowsableState.Advanced)]
1428         public void RegisterRequiresPostBack (Control control)
1429         {
1430                 if (_requiresPostBack == null)
1431                         _requiresPostBack = new ArrayList ();
1432
1433                 _requiresPostBack.Add (control.UniqueID);
1434         }
1435
1436         [EditorBrowsable (EditorBrowsableState.Advanced)]
1437         public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1438         {
1439                 requiresRaiseEvent = control;
1440         }
1441
1442 #if NET_2_0
1443         [Obsolete]
1444 #endif
1445         [EditorBrowsable (EditorBrowsableState.Advanced)]
1446         public virtual void RegisterStartupScript (string key, string script)
1447         {
1448                 scriptManager.RegisterStartupScript (key, script);
1449         }
1450
1451         [EditorBrowsable (EditorBrowsableState.Advanced)]
1452         public void RegisterViewStateHandler ()
1453         {
1454                 handleViewState = true;
1455         }
1456
1457         [EditorBrowsable (EditorBrowsableState.Advanced)]
1458         protected virtual void SavePageStateToPersistenceMedium (object viewState)
1459         {
1460                 _savedViewState = viewState;
1461         }
1462
1463         [EditorBrowsable (EditorBrowsableState.Advanced)]
1464         protected virtual object LoadPageStateFromPersistenceMedium ()
1465         {
1466                 NameValueCollection postdata = _requestValueCollection;
1467                 string view_state;
1468                 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1469                         return null;
1470
1471                 if (view_state == "")
1472                         return null;
1473
1474                 LosFormatter fmt = GetFormatter ();
1475                 try {
1476                         return fmt.Deserialize (view_state);
1477                 } catch (Exception e) {
1478                         throw new HttpException ("Error restoring page viewstate.", e);
1479                 }
1480         }
1481
1482         internal void LoadPageViewState()
1483         {
1484                 object sState = LoadPageStateFromPersistenceMedium ();
1485                 if (sState != null) {
1486 #if NET_2_0
1487                         Triplet data = (Triplet) sState;
1488                         if (allow_load) {
1489                                 LoadPageControlState (data.Third);
1490                                 LoadViewStateRecursive (data.First);
1491                                 _requiresPostBack = data.Second as ArrayList;
1492                         }
1493 #else
1494                         Pair pair = (Pair) sState;
1495                         if (allow_load) {
1496                                 LoadViewStateRecursive (pair.First);
1497                                 _requiresPostBack = pair.Second as ArrayList;
1498                         }
1499 #endif
1500                 }
1501         }
1502
1503         internal void SavePageViewState ()
1504         {
1505                 if (!handleViewState)
1506                         return;
1507
1508 #if NET_2_0
1509                 object controlState = SavePageControlState ();
1510 #endif
1511
1512                 object viewState = SaveViewStateRecursive ();
1513                 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1514
1515 #if NET_2_0
1516                 Triplet triplet = new Triplet ();
1517                 triplet.First = viewState;
1518                 triplet.Second = reqPostback;
1519                 triplet.Third = controlState;
1520
1521                 if (triplet.First == null && triplet.Second == null && triplet.Third == null)
1522                         triplet = null;
1523                         
1524                 SavePageStateToPersistenceMedium (triplet);
1525 #else
1526                 Pair pair = new Pair ();
1527                 pair.First = viewState;
1528                 pair.Second = reqPostback;
1529
1530                 if (pair.First == null && pair.Second == null)
1531                         pair = null;
1532                         
1533                 SavePageStateToPersistenceMedium (pair);
1534 #endif
1535         }
1536
1537         public virtual void Validate ()
1538         {
1539                 is_validated = true;
1540                 ValidateCollection (_validators);
1541         }
1542
1543 #if NET_2_0
1544         internal bool AreValidatorsUplevel () {
1545                 return AreValidatorsUplevel (String.Empty);
1546         }
1547
1548         internal bool AreValidatorsUplevel (string valGroup)
1549 #else
1550         internal virtual bool AreValidatorsUplevel ()
1551 #endif
1552         {
1553                 bool uplevel = false;
1554
1555                 foreach (IValidator v in Validators) {
1556                         BaseValidator bv = v as BaseValidator;
1557                         if (bv == null) continue;
1558
1559 #if NET_2_0
1560                         if (valGroup != bv.ValidationGroup)
1561                                 continue;
1562 #endif
1563                         if (bv.GetRenderUplevel()) {
1564                                 uplevel = true;
1565                                 break;
1566                         }
1567                 }
1568
1569                 return uplevel;
1570         }
1571
1572         bool ValidateCollection (ValidatorCollection validators)
1573         {
1574 #if NET_2_0
1575                 if (!_eventValidation)
1576                         return true;
1577 #endif
1578
1579                 if (validators == null || validators.Count == 0)
1580                         return true;
1581
1582                 bool all_valid = true;
1583                 foreach (IValidator v in validators){
1584                         v.Validate ();
1585                         if (v.IsValid == false)
1586                                 all_valid = false;
1587                 }
1588
1589                 return all_valid;
1590         }
1591
1592         [EditorBrowsable (EditorBrowsableState.Advanced)]
1593         public virtual void VerifyRenderingInServerForm (Control control)
1594         {
1595                 if (_context == null)
1596                         return;
1597
1598                 if (!renderingForm)
1599                         throw new HttpException ("Control '" +
1600                                                  control.ClientID +
1601                                                  "' of type '" +
1602                                                  control.GetType ().Name +
1603                                                  "' must be placed inside a form tag with runat=server.");
1604         }
1605
1606         protected override void FrameworkInitialize ()
1607         {
1608                 base.FrameworkInitialize ();
1609 #if NET_2_0
1610                 InitializeStyleSheet ();
1611 #endif
1612         }
1613
1614         #endregion
1615         
1616         #if NET_2_0
1617         public
1618         #else
1619         internal
1620         #endif
1621                 ClientScriptManager ClientScript {
1622                 get { return scriptManager; }
1623         }
1624         
1625         #if NET_2_0
1626         
1627         static readonly object InitCompleteEvent = new object ();
1628         static readonly object LoadCompleteEvent = new object ();
1629         static readonly object PreInitEvent = new object ();
1630         static readonly object PreLoadEvent = new object ();
1631         static readonly object PreRenderCompleteEvent = new object ();
1632         static readonly object SaveStateCompleteEvent = new object ();
1633         int event_mask;
1634         const int initcomplete_mask = 1;
1635         const int loadcomplete_mask = 1 << 1;
1636         const int preinit_mask = 1 << 2;
1637         const int preload_mask = 1 << 3;
1638         const int prerendercomplete_mask = 1 << 4;
1639         const int savestatecomplete_mask = 1 << 5;
1640         
1641         [EditorBrowsable (EditorBrowsableState.Advanced)]
1642         public event EventHandler InitComplete {
1643                 add {
1644                         event_mask |= initcomplete_mask;
1645                         Events.AddHandler (InitCompleteEvent, value);
1646                 }
1647                 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1648         }
1649         
1650         [EditorBrowsable (EditorBrowsableState.Advanced)]
1651         public event EventHandler LoadComplete {
1652                 add {
1653                         event_mask |= loadcomplete_mask;
1654                         Events.AddHandler (LoadCompleteEvent, value);
1655                 }
1656                 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1657         }
1658         
1659         public event EventHandler PreInit {
1660                 add {
1661                         event_mask |= preinit_mask;
1662                         Events.AddHandler (PreInitEvent, value);
1663                 }
1664                 remove { Events.RemoveHandler (PreInitEvent, value); }
1665         }
1666         
1667         [EditorBrowsable (EditorBrowsableState.Advanced)]
1668         public event EventHandler PreLoad {
1669                 add {
1670                         event_mask |= preload_mask;
1671                         Events.AddHandler (PreLoadEvent, value);
1672                 }
1673                 remove { Events.RemoveHandler (PreLoadEvent, value); }
1674         }
1675         
1676         [EditorBrowsable (EditorBrowsableState.Advanced)]
1677         public event EventHandler PreRenderComplete {
1678                 add {
1679                         event_mask |= prerendercomplete_mask;
1680                         Events.AddHandler (PreRenderCompleteEvent, value);
1681                 }
1682                 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
1683         }
1684         
1685         [EditorBrowsable (EditorBrowsableState.Advanced)]
1686         public event EventHandler SaveStateComplete {
1687                 add {
1688                         event_mask |= savestatecomplete_mask;
1689                         Events.AddHandler (SaveStateCompleteEvent, value);
1690                 }
1691                 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
1692         }
1693         
1694         protected virtual void OnInitComplete (EventArgs e)
1695         {
1696                 if ((event_mask & initcomplete_mask) != 0) {
1697                         EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
1698                         if (eh != null) eh (this, e);
1699                 }
1700         }
1701         
1702         protected virtual void OnLoadComplete (EventArgs e)
1703         {
1704                 if ((event_mask & loadcomplete_mask) != 0) {
1705                         EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
1706                         if (eh != null) eh (this, e);
1707                 }
1708         }
1709         
1710         protected virtual void OnPreInit (EventArgs e)
1711         {
1712                 if ((event_mask & preinit_mask) != 0) {
1713                         EventHandler eh = (EventHandler) (Events [PreInitEvent]);
1714                         if (eh != null) eh (this, e);
1715                 }
1716         }
1717         
1718         protected virtual void OnPreLoad (EventArgs e)
1719         {
1720                 if ((event_mask & preload_mask) != 0) {
1721                         EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
1722                         if (eh != null) eh (this, e);
1723                 }
1724         }
1725         
1726         protected virtual void OnPreRenderComplete (EventArgs e)
1727         {
1728                 if ((event_mask & prerendercomplete_mask) != 0) {
1729                         EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
1730                         if (eh != null) eh (this, e);
1731                 }
1732
1733                 if (Form == null)
1734                         return;
1735                 if (!Form.DetermineRenderUplevel ())
1736                         return;
1737
1738                 /* figure out if we have some control we're going to focus */
1739                 if (String.IsNullOrEmpty (_focusedControlID)) {
1740                         _focusedControlID = Form.DefaultFocus;
1741                         if (String.IsNullOrEmpty (_focusedControlID))
1742                                 _focusedControlID = Form.DefaultButton;
1743                 }
1744
1745                 if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
1746
1747                         RequiresPostBackScript ();
1748                         ClientScript.RegisterWebFormClientScript ();
1749
1750                         if (!String.IsNullOrEmpty (_focusedControlID)) {
1751                                 ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
1752                                                                          String.Format ("<script type=\"text/javascript\">\n" +
1753                                                                                         "<!--\n" +
1754                                                                                         "WebForm_AutoFocus('{0}');// -->\n" +
1755                                                                                         "</script>\n", _focusedControlID));
1756                         }
1757
1758                         if (Form.SubmitDisabledControls) {
1759                                 ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
1760                                                                                  "javascript: return WebForm_OnSubmit();");
1761                                 ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
1762 @"<script language=""JavaScript"">
1763 <!--
1764 function WebForm_OnSubmit() {
1765 WebForm_ReEnableControls();
1766 return true;
1767 } // -->
1768 </script>");
1769                         }
1770                 }
1771         }
1772         
1773         protected virtual void OnSaveStateComplete (EventArgs e)
1774         {
1775                 if ((event_mask & savestatecomplete_mask) != 0) {
1776                         EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
1777                         if (eh != null) eh (this, e);
1778                 }
1779         }
1780         
1781         public HtmlForm Form {
1782                 get { return _form; }
1783         }
1784         
1785         internal void RegisterForm (HtmlForm form)
1786         {
1787                 _form = form;
1788         }
1789         
1790         [BrowsableAttribute (false)]
1791         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1792         public Page PreviousPage {
1793                 get {
1794                         if (_doLoadPreviousPage) {
1795                                 _doLoadPreviousPage = false;
1796                                 LoadPreviousPageReference ();
1797                         }
1798                         return previousPage;
1799                 }
1800         }
1801
1802         
1803         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1804         [BrowsableAttribute (false)]
1805         public bool IsCallback {
1806                 get { return isCallback; }
1807         }
1808         
1809         [BrowsableAttribute (false)]
1810         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1811         public bool IsCrossPagePostBack {
1812                 get { return isCrossPagePostBack; }
1813         }
1814         
1815         string ProcessCallbackData ()
1816         {
1817                 string callbackTarget = _requestValueCollection [CallbackSourceID];
1818                 if (callbackTarget == null || callbackTarget.Length == 0)
1819                         throw new HttpException ("Callback target not provided.");
1820
1821                 Control targetControl = FindControl (callbackTarget);
1822                 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
1823                 if (target == null)
1824                         throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
1825
1826                 string callbackArgument = _requestValueCollection [CallbackArgumentID];
1827                 if (CheckForValidationSupport (targetControl))
1828                         scriptManager.ValidateEvent (targetControl.UniqueID, callbackArgument);
1829                 target.RaiseCallbackEvent (callbackArgument);
1830                 return target.GetCallbackResult ();
1831         }
1832
1833         [BrowsableAttribute (false)]
1834         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1835         public HtmlHead Header {
1836                 get { return htmlHeader; }
1837         }
1838         
1839         internal void SetHeader (HtmlHead header)
1840         {
1841                 htmlHeader = header;
1842                 if (_title != null) {
1843                         htmlHeader.Title = _title;
1844                         _title = null;
1845                 }
1846         }
1847
1848         [MonoTODO("Not Implemented")]
1849         protected bool AsyncMode {
1850                 get {
1851                         throw new NotImplementedException ();
1852                 }
1853                 set {
1854                         throw new NotImplementedException ();
1855                 }
1856         }
1857
1858         [MonoTODO ("Not Implemented")]
1859         public TimeSpan AsyncTimeout {
1860                 get {
1861                         throw new NotImplementedException ();
1862                 }
1863                 set {
1864                         throw new NotImplementedException ();
1865                 }
1866         }
1867
1868         [MonoTODO ("Not Implemented")]
1869         public bool IsAsync {
1870                 get {
1871                         throw new NotImplementedException ();
1872                 }
1873         }
1874         
1875         [MonoTODO ("Not Implemented")]
1876         protected internal virtual string UniqueFilePathSuffix {
1877                 get {
1878                         throw new NotImplementedException ();
1879                 }
1880         }
1881
1882         [MonoTODO ("Not Implemented")]
1883         public int MaxPageStateFieldLength {
1884                 get {
1885                         throw new NotImplementedException ();
1886                 }
1887                 set {
1888                         throw new NotImplementedException ();
1889                 }
1890         }
1891
1892         [MonoTODO ("Not Implemented")]
1893         public ViewStateEncryptionMode ViewStateEncryptionMode {
1894                 get {
1895                         throw new NotImplementedException ();
1896                 }
1897                 set {
1898                         throw new NotImplementedException ();
1899                 }
1900         }
1901
1902         [MonoTODO ("Not Implemented")]
1903         public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
1904         {
1905                 throw new NotImplementedException ();
1906         }
1907
1908         [MonoTODO ("Not Implemented")]
1909         public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
1910         {
1911                 throw new NotImplementedException ();
1912         }
1913
1914         [MonoTODO ("Not Implemented")]
1915         public void ExecuteRegisteredAsyncTasks ()
1916         {
1917                 throw new NotImplementedException ();
1918         }
1919
1920         [MonoTODO ("Not Implemented")]
1921         public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
1922         {
1923                 throw new NotImplementedException ();
1924         }
1925
1926         [MonoTODO ("Not Implemented")]
1927         public void RegisterRequiresViewStateEncryption ()
1928         {
1929                 throw new NotImplementedException ();
1930         }
1931
1932         void ApplyMasterPage ()
1933         {
1934                 if (masterPageFile != null && masterPageFile.Length > 0) {
1935                         ArrayList appliedMasterPageFiles = new ArrayList ();
1936
1937                         if (Master != null) {
1938                                 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
1939
1940                                 Master.Page = this;
1941                                 Controls.Clear ();
1942                                 Controls.Add (Master);
1943                         }
1944                 }
1945         }
1946
1947         [DefaultValueAttribute ("")]
1948         public virtual string MasterPageFile {
1949                 get { return masterPageFile; }
1950                 set {
1951                         masterPageFile = value;
1952                         masterPage = null;
1953                 }
1954         }
1955         
1956         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1957         [BrowsableAttribute (false)]
1958         public MasterPage Master {
1959                 get {
1960                         if (Context == null || String.IsNullOrEmpty (masterPageFile))
1961                                 return null;
1962
1963                         if (masterPage == null)
1964                                 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
1965
1966                         return masterPage;
1967                 }
1968         }
1969         
1970         public void SetFocus (string clientID)
1971         {
1972                 if (String.IsNullOrEmpty (clientID))
1973                         throw new ArgumentNullException ("control");
1974
1975                 if (_lifeCycle > PageLifeCycle.PreRender)
1976                         throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
1977
1978                 if(Form==null)
1979                         throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
1980
1981                 _focusedControlID = clientID;
1982         }
1983
1984         public void SetFocus (Control control)
1985         {
1986                 if (control == null)
1987                         throw new ArgumentNullException ("control");
1988
1989                 SetFocus (control.ClientID);
1990         }
1991         
1992         [EditorBrowsable (EditorBrowsableState.Advanced)]
1993         public void RegisterRequiresControlState (Control control)
1994         {
1995                 if (control == null)
1996                         throw new ArgumentNullException ("control");
1997
1998                 if (RequiresControlState (control))
1999                         return;
2000
2001                 if (requireStateControls == null)
2002                         requireStateControls = new ArrayList ();
2003                 int n = requireStateControls.Add (control);
2004
2005                 if (_savedControlState == null || n >= _savedControlState.Length) 
2006                         return;
2007
2008                 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2009                         if (parent.IsChildControlStateCleared)
2010                                 return;
2011
2012                 object state = _savedControlState [n];
2013                 if (state != null)
2014                         control.LoadControlState (state);
2015         }
2016         
2017         public bool RequiresControlState (Control control)
2018         {
2019                 if (requireStateControls == null) return false;
2020                 return requireStateControls.Contains (control);
2021         }
2022         
2023         [EditorBrowsable (EditorBrowsableState.Advanced)]
2024         public void UnregisterRequiresControlState (Control control)
2025         {
2026                 if (requireStateControls != null)
2027                         requireStateControls.Remove (control);
2028         }
2029         
2030         public ValidatorCollection GetValidators (string validationGroup)
2031         {
2032                 string valgr = validationGroup;
2033                 if (valgr == null)
2034                         valgr = String.Empty;
2035
2036                 if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
2037                 ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
2038                 if (col == null) {
2039                         col = new ValidatorCollection ();
2040                         _validatorsByGroup [valgr] = col;
2041                 }
2042                 return col;
2043         }
2044         
2045         public virtual void Validate (string validationGroup)
2046         {
2047                 is_validated = true;
2048                 if (validationGroup == null)
2049                         ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
2050                 else if (_validatorsByGroup != null) {
2051                         ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
2052                 }
2053         }
2054
2055         object SavePageControlState ()
2056         {
2057                 if (requireStateControls == null) return null;
2058                 object[] state = new object [requireStateControls.Count];
2059                 
2060                 bool allNull = true;
2061                 for (int n=0; n<state.Length; n++) {
2062                         state [n] = ((Control) requireStateControls [n]).SaveControlState ();
2063                         if (state [n] != null) allNull = false;
2064                 }
2065                 if (allNull) return null;
2066                 else return state;
2067         }
2068         
2069         void LoadPageControlState (object data)
2070         {
2071                 _savedControlState = (object []) data;
2072                 
2073                 if (requireStateControls == null) return;
2074
2075                 int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2076                 for (int n=0; n < max; n++) {
2077                         Control ctl = (Control) requireStateControls [n];
2078                         ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2079                 }
2080         }
2081
2082         void LoadPreviousPageReference ()
2083         {
2084                 if (_requestValueCollection != null) {
2085                         string prevPage = _requestValueCollection [PreviousPageID];
2086                         if (prevPage != null) {
2087                                 previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
2088                                 previousPage.ProcessCrossPagePostBack (_context);
2089                         } 
2090                 }
2091         }
2092
2093
2094         Hashtable contentTemplates;
2095         [EditorBrowsable (EditorBrowsableState.Never)]
2096         protected internal void AddContentTemplate (string templateName, ITemplate template)
2097         {
2098                 if (contentTemplates == null)
2099                         contentTemplates = new Hashtable ();
2100                 contentTemplates [templateName] = template;
2101         }
2102
2103         PageTheme _pageTheme;
2104         internal PageTheme PageTheme {
2105                 get { return _pageTheme; }
2106         }
2107
2108         PageTheme _styleSheetPageTheme;
2109         internal PageTheme StyleSheetPageTheme {
2110                 get { return _styleSheetPageTheme; }
2111         }
2112
2113         Stack dataItemCtx;
2114         
2115         internal void PushDataItemContext (object o) {
2116                 if (dataItemCtx == null)
2117                         dataItemCtx = new Stack ();
2118                 
2119                 dataItemCtx.Push (o);
2120         }
2121         
2122         internal void PopDataItemContext () {
2123                 if (dataItemCtx == null)
2124                         throw new InvalidOperationException ();
2125                 
2126                 dataItemCtx.Pop ();
2127         }
2128         
2129         public object GetDataItem() {
2130                 if (dataItemCtx == null || dataItemCtx.Count == 0)
2131                         throw new InvalidOperationException ("No data item");
2132                 
2133                 return dataItemCtx.Peek ();
2134         }
2135
2136         protected internal override void OnInit (EventArgs e)
2137         {
2138                 base.OnInit (e);
2139                 if (Header == null)
2140                         return;
2141
2142                 ArrayList themes = new ArrayList();
2143
2144                 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2145                         themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2146                 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2147                         themes.AddRange (PageTheme.GetStyleSheets ());
2148
2149                 foreach (string lss in themes) {
2150                         HtmlLink hl = new HtmlLink ();
2151                         hl.Href = ResolveUrl (lss);
2152                         hl.Attributes["type"] = "text/css";
2153                         hl.Attributes["rel"] = "stylesheet";
2154                         Header.Controls.Add (hl);
2155                 }
2156         }
2157
2158         #endif
2159
2160 #if NET_2_0
2161         [MonoTODO ("Not implemented.  Only used by .net aspx parser")]
2162         protected object GetWrappedFileDependencies (string [] list)
2163         {
2164                 return null;
2165         }
2166
2167         [MonoTODO ("Does nothing.  Used by .net aspx parser")]
2168         protected virtual void InitializeCulture ()
2169         {
2170         }
2171
2172         [MonoTODO ("Does nothing. Used by .net aspx parser")]
2173         protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
2174         {
2175         }
2176 #endif
2177 }
2178 }