refactoring.
[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 using System.Collections.Generic;
55 using System.Reflection;
56 #endif
57
58 namespace System.Web.UI
59 {
60 // CAS
61 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
62 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
63 #if !NET_2_0
64 [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
65 #endif
66 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
67 [ToolboxItem (false)]
68 #if NET_2_0
69 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
70 #else
71 [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
72 #endif
73 public partial class Page : TemplateControl, IHttpHandler
74 {
75         static string machineKeyConfigPath = "system.web/machineKey";
76 #if NET_2_0
77         private PageLifeCycle _lifeCycle = PageLifeCycle.Unknown;
78         private bool _eventValidation = true;
79         private object [] _savedControlState;
80         private bool _doLoadPreviousPage;
81         string _focusedControlID;
82         bool _hasEnabledControlArray;
83 #endif
84         private bool _viewState = true;
85         private bool _viewStateMac;
86         private string _errorPage;
87         private bool is_validated;
88         private bool _smartNavigation;
89         private int _transactionMode;
90         private ValidatorCollection _validators;
91         private bool renderingForm;
92         private string _savedViewState;
93         private ArrayList _requiresPostBack;
94         private ArrayList _requiresPostBackCopy;
95         private ArrayList requiresPostDataChanged;
96         private IPostBackEventHandler requiresRaiseEvent;
97         private NameValueCollection secondPostData;
98         private bool requiresPostBackScript;
99         private bool postBackScriptRendered;
100         bool handleViewState;
101         string viewStateUserKey;
102         NameValueCollection _requestValueCollection;
103         string clientTarget;
104         ClientScriptManager scriptManager;
105         bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
106         PageStatePersister page_state_persister;
107         CultureInfo _appCulture;
108         CultureInfo _appUICulture;
109
110         // The initial context
111         private HttpContext _context;
112         
113         // cached from the initial context
114         HttpApplicationState _application;
115         HttpResponse _response;
116         HttpRequest _request;
117         Cache _cache;
118         
119         HttpSessionState _session;
120         
121         [EditorBrowsable (EditorBrowsableState.Never)]
122 #if NET_2_0
123         public
124 #else
125         protected
126 #endif
127         const string postEventArgumentID = "__EVENTARGUMENT";
128
129         [EditorBrowsable (EditorBrowsableState.Never)]
130 #if NET_2_0
131         public
132 #else
133         protected
134 #endif
135         const string postEventSourceID = "__EVENTTARGET";
136
137 #if NET_2_0
138         const string ScrollPositionXID = "__SCROLLPOSITIONX";
139         const string ScrollPositionYID = "__SCROLLPOSITIONY";
140         const string EnabledControlArrayID = "__enabledControlArray";
141 #endif
142
143 #if NET_2_0
144         internal const string LastFocusID = "__LASTFOCUS";
145         internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
146         internal const string CallbackSourceID = "__CALLBACKTARGET";
147         internal const string PreviousPageID = "__PREVIOUSPAGE";
148
149         HtmlHead htmlHeader;
150         
151         MasterPage masterPage;
152         string masterPageFile;
153         
154         Page previousPage;
155         bool isCrossPagePostBack;
156         bool isPostBack;
157         bool isCallback;
158         ArrayList requireStateControls;
159         HtmlForm _form;
160
161         string _title;
162         string _theme;
163         string _styleSheetTheme;
164         Hashtable items;
165
166         bool _maintainScrollPositionOnPostBack;
167
168         private bool asyncMode = false;
169         private TimeSpan asyncTimeout;
170         private const double DefaultAsyncTimeout = 45.0;
171         private List<PageAsyncTask> parallelTasks;
172         private List<PageAsyncTask> serialTasks;
173
174         private ViewStateEncryptionMode viewStateEncryptionMode;
175         private bool controlRegisteredForViewStateEncryption = false;
176 #endif
177
178         #region Constructor
179         public Page ()
180         {
181                 scriptManager = new ClientScriptManager (this);
182                 Page = this;
183                 ID = "__Page";
184                 
185 #if NET_2_0
186                 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
187                 if (ps != null) {
188                         asyncTimeout = ps.AsyncTimeout;
189                         viewStateEncryptionMode = ps.ViewStateEncryptionMode;
190                 } else {
191                         asyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
192                         viewStateEncryptionMode = ViewStateEncryptionMode.Auto;
193                 }
194 #endif
195         }
196
197         #endregion              
198
199         #region Properties
200
201         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
202         [Browsable (false)]
203         public HttpApplicationState Application {
204                 get { return _application; }
205         }
206
207         [EditorBrowsable (EditorBrowsableState.Never)]
208         protected bool AspCompatMode {
209 #if NET_2_0
210                 get { return false; }
211 #endif
212                 set { throw new NotImplementedException (); }
213         }
214
215         [EditorBrowsable (EditorBrowsableState.Never)]
216 #if NET_2_0
217         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
218         [BrowsableAttribute (false)]
219         public bool Buffer {
220                 get { return Response.BufferOutput; }
221                 set { Response.BufferOutput = value; }
222         }
223 #else
224         protected bool Buffer {
225                 set { Response.BufferOutput = value; }
226         }
227 #endif
228
229         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
230         [Browsable (false)]
231         public Cache Cache {
232                 get {
233                         if (_cache == null)
234                                 throw new HttpException ("Cache is not available.");
235                         return _cache;
236                 }
237         }
238
239 #if NET_2_0
240         [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
241 #endif
242         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
243         [Browsable (false), DefaultValue ("")]
244         [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
245         public string ClientTarget {
246                 get { return (clientTarget == null) ? "" : clientTarget; }
247                 set {
248                         clientTarget = value;
249                         if (value == "")
250                                 clientTarget = null;
251                 }
252         }
253
254         [EditorBrowsable (EditorBrowsableState.Never)]
255 #if NET_2_0
256         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
257         [BrowsableAttribute (false)]
258         public int CodePage {
259                 get { return Response.ContentEncoding.CodePage; }
260                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
261         }
262 #else
263         protected int CodePage {
264                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
265         }
266 #endif
267
268         [EditorBrowsable (EditorBrowsableState.Never)]
269 #if NET_2_0
270         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
271         [BrowsableAttribute (false)]
272         public string ContentType {
273                 get { return Response.ContentType; }
274                 set { Response.ContentType = value; }
275         }
276 #else
277         protected string ContentType {
278                 set { Response.ContentType = value; }
279         }
280 #endif
281
282         protected override HttpContext Context {
283                 get {
284                         if (_context == null)
285                                 return HttpContext.Current;
286
287                         return _context;
288                 }
289         }
290
291 #if NET_2_0
292         [EditorBrowsable (EditorBrowsableState.Advanced)]
293         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
294         [BrowsableAttribute (false)]
295         public string Culture {
296                 get { return Thread.CurrentThread.CurrentCulture.Name; }
297                 set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
298         }
299 #else
300         [EditorBrowsable (EditorBrowsableState.Never)]
301         protected string Culture {
302                 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
303         }
304 #endif
305
306 #if NET_2_0
307         public virtual bool EnableEventValidation {
308                 get { return _eventValidation; }
309                 set {
310                         if (_lifeCycle > PageLifeCycle.Init)
311                                 throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
312                         _eventValidation = value;
313                 }
314         }
315
316         internal PageLifeCycle LifeCycle {
317                 get { return _lifeCycle; }
318         }
319 #endif
320
321         [Browsable (false)]
322         public override bool EnableViewState {
323                 get { return _viewState; }
324                 set { _viewState = value; }
325         }
326
327 #if NET_2_0
328         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
329         [BrowsableAttribute (false)]
330 #endif
331         [EditorBrowsable (EditorBrowsableState.Never)]
332 #if NET_2_0
333         public
334 #else
335         protected
336 #endif
337         bool EnableViewStateMac {
338                 get { return _viewStateMac; }
339                 set { _viewStateMac = value; }
340         }
341
342 #if NET_1_1
343         internal bool EnableViewStateMacInternal {
344                 get { return _viewStateMac; }
345                 set { _viewStateMac = value; }
346         }
347 #endif
348         
349         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
350         [Browsable (false), DefaultValue ("")]
351         [WebSysDescription ("The URL of a page used for error redirection.")]
352         public string ErrorPage {
353                 get { return _errorPage; }
354                 set {
355                         HttpContext ctx = Context;
356                         
357                         _errorPage = value;
358                         if (ctx != null)
359                                 ctx.ErrorPage = value;
360                 }
361         }
362
363 #if NET_2_0
364         [Obsolete]
365 #endif
366         [EditorBrowsable (EditorBrowsableState.Never)]
367         protected ArrayList FileDependencies {
368                 set {
369                         if (Response != null)
370                                 Response.AddFileDependencies (value);
371                 }
372         }
373
374         [Browsable (false)]
375 #if NET_2_0
376         [EditorBrowsable (EditorBrowsableState.Never)]
377 #endif
378         public override string ID {
379                 get { return base.ID; }
380                 set { base.ID = value; }
381         }
382
383         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
384         [Browsable (false)]
385         public bool IsPostBack {
386                 get {
387 #if NET_2_0
388                         return isPostBack;
389 #else
390                         return _requestValueCollection != null;
391 #endif
392                 }
393         }
394
395         [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
396         public bool IsReusable {
397                 get { return false; }
398         }
399
400         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
401         [Browsable (false)]
402         public bool IsValid {
403                 get {
404                         if (!is_validated)
405                                 throw new HttpException (Locale.GetText ("Page hasn't been validated."));
406
407 #if NET_2_0
408                         foreach (IValidator val in Validators)
409                                 if (!val.IsValid)
410                                         return false;
411                         return true;
412 #else
413                         return ValidateCollection (_validators);
414 #endif
415                 }
416         }
417 #if NET_2_0
418         public IDictionary Items {
419                 get {
420                         if (items == null)
421                                 items = new Hashtable ();
422                         return items;
423                 }
424         }
425 #endif
426
427         [EditorBrowsable (EditorBrowsableState.Never)]
428 #if NET_2_0
429         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
430         [BrowsableAttribute (false)]
431         public int LCID {
432                 get { return Thread.CurrentThread.CurrentCulture.LCID; }
433                 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
434         }
435 #else
436         protected int LCID {
437                 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
438         }
439 #endif
440
441 #if NET_2_0
442         [Browsable (false)]
443         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
444         public bool MaintainScrollPositionOnPostBack {
445                 get { return _maintainScrollPositionOnPostBack; }
446                 set { _maintainScrollPositionOnPostBack = value; }
447         }
448 #endif
449
450 #if NET_2_0
451         public PageAdapter PageAdapter {
452                 get {
453                         return (PageAdapter)Adapter;
454                 }
455         }
456 #endif
457
458 #if !TARGET_J2EE
459         internal string theForm {
460                 get {
461                         return "theForm";
462                 }
463         }
464         
465         internal bool IsMultiForm {
466                 get { return false; }
467         }
468 #endif
469
470         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
471         [Browsable (false)]
472         public HttpRequest Request {
473                 get {
474                         if (_request == null)
475                                 throw new HttpException("Request is not available in this context.");
476                         return _request;
477                 }
478         }
479
480         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
481         [Browsable (false)]
482         public HttpResponse Response {
483                 get {
484                         if (_response == null)
485                                 throw new HttpException ("Response is not available in this context.");
486                         return _response;
487                 }
488         }
489
490         [EditorBrowsable (EditorBrowsableState.Never)]
491 #if NET_2_0
492         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
493         [BrowsableAttribute (false)]
494         public string ResponseEncoding {
495                 get { return Response.ContentEncoding.WebName; }
496                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
497         }
498 #else
499         protected string ResponseEncoding {
500                 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
501         }
502 #endif
503
504         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
505         [Browsable (false)]
506         public HttpServerUtility Server {
507                 get { return Context.Server; }
508         }
509
510         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
511         [Browsable (false)]
512         public virtual HttpSessionState Session {
513                 get {
514                         if (_session != null)
515                                 return _session;
516
517                         try {
518                                 _session = Context.Session;
519                         } catch {
520                                 // ignore, should not throw
521                         }
522                         
523                         if (_session == null)
524                                 throw new HttpException ("Session state can only be used " +
525                                                 "when enableSessionState is set to true, either " +
526                                                 "in a configuration file or in the Page directive.");
527
528                         return _session;
529                 }
530         }
531
532 #if NET_2_0
533         [FilterableAttribute (false)]
534         [Obsolete]
535 #endif
536         [Browsable (false)]
537         public bool SmartNavigation {
538                 get { return _smartNavigation; }
539                 set { _smartNavigation = value; }
540         }
541
542 #if NET_2_0
543         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
544         [Filterable (false)]
545         [Browsable (false)]
546         public virtual string StyleSheetTheme {
547                 get { return _styleSheetTheme; }
548                 set { _styleSheetTheme = value; }
549         }
550
551         [Browsable (false)]
552         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
553         public virtual string Theme {
554                 get { return _theme; }
555                 set { _theme = value; }
556         }
557
558         void InitializeStyleSheet ()
559         {
560                 if (_styleSheetTheme == null) {
561                         PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
562                         if (ps != null)
563                                 _styleSheetTheme = ps.StyleSheetTheme;
564                 }
565                 if (_styleSheetTheme != null && _styleSheetTheme != "")
566                         _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, Context);
567         }
568
569         void InitializeTheme ()
570         {
571                 if (_theme == null) {
572                         PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
573                         if (ps != null)
574                                 _theme = ps.Theme;
575                 }
576                 if (_theme != null && _theme != "") {
577                         _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, Context);
578                         _pageTheme.SetPage (this);
579                 }
580         }
581
582 #endif
583
584 #if NET_2_0
585         [Localizable (true)] 
586         [Bindable (true)] 
587         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
588         public string Title {
589                 get {
590                         if (_title == null) {
591                                 if (htmlHeader != null)
592                                         return htmlHeader.Title;
593                                 return String.Empty;
594                         }
595                         return _title;
596                 }
597                 set {
598                         if (htmlHeader != null)
599                                 htmlHeader.Title = value;
600                         else
601                                 _title = value;
602                 }
603         }
604 #endif
605
606         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
607         [Browsable (false)]
608         public TraceContext Trace {
609                 get { return Context.Trace; }
610         }
611
612         [EditorBrowsable (EditorBrowsableState.Never)]
613 #if NET_2_0
614         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
615         [BrowsableAttribute (false)]
616         public bool TraceEnabled {
617                 get { return Trace.IsEnabled; }
618                 set { Trace.IsEnabled = value; }
619         }
620 #else
621         protected bool TraceEnabled {
622                 set { Trace.IsEnabled = value; }
623         }
624 #endif
625
626         [EditorBrowsable (EditorBrowsableState.Never)]
627 #if NET_2_0
628         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
629         [BrowsableAttribute (false)]
630         public TraceMode TraceModeValue {
631                 get { return Trace.TraceMode; }
632                 set { Trace.TraceMode = value; }
633         }
634 #else
635         protected TraceMode TraceModeValue {
636                 set { Trace.TraceMode = value; }
637         }
638 #endif
639
640         [EditorBrowsable (EditorBrowsableState.Never)]
641         protected int TransactionMode {
642 #if NET_2_0
643                 get { return _transactionMode; }
644 #endif
645                 set { _transactionMode = value; }
646         }
647
648 #if !NET_2_0
649         //
650         // This method is here just to remove the warning about "_transactionMode" not being
651         // used.  We probably will use it internally at some point.
652         //
653         internal int GetTransactionMode ()
654         {
655                 return _transactionMode;
656         }
657 #endif
658         
659 #if NET_2_0
660         [EditorBrowsable (EditorBrowsableState.Advanced)]
661         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
662         [BrowsableAttribute (false)]
663         public string UICulture {
664                 get { return Thread.CurrentThread.CurrentUICulture.Name; }
665                 set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
666         }
667 #else
668         [EditorBrowsable (EditorBrowsableState.Never)]
669         protected string UICulture {
670                 set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
671         }
672 #endif
673
674         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
675         [Browsable (false)]
676         public IPrincipal User {
677                 get { return Context.User; }
678         }
679
680         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
681         [Browsable (false)]
682         public ValidatorCollection Validators {
683                 get { 
684                         if (_validators == null)
685                                 _validators = new ValidatorCollection ();
686                         return _validators;
687                 }
688         }
689
690         [MonoTODO ("Use this when encrypting/decrypting ViewState")]
691         [Browsable (false)]
692         public string ViewStateUserKey {
693                 get { return viewStateUserKey; }
694                 set { viewStateUserKey = value; }
695         }
696
697         [Browsable (false)]
698         public override bool Visible {
699                 get { return base.Visible; }
700                 set { base.Visible = value; }
701         }
702
703         #endregion
704
705         #region Methods
706
707 #if NET_2_0
708         CultureInfo GetPageCulture (string culture, CultureInfo deflt)
709         {
710                 if (culture == null)
711                         return deflt;
712                 CultureInfo ret = null;
713                 if (culture.StartsWith ("auto", StringComparison.InvariantCultureIgnoreCase)) {
714 #if TARGET_J2EE
715                         //if (Context.IsPortletRequest)
716                                 return deflt;
717 #endif
718                         string[] languages = Request.UserLanguages;
719                         try {
720                                 if (languages != null && languages.Length > 0)
721                                         ret = CultureInfo.CreateSpecificCulture (languages[0]);
722                         } catch {
723                         }
724                         
725                         if (ret == null)
726                                 ret = deflt;
727                 } else
728                         ret = CultureInfo.CreateSpecificCulture (culture);
729
730                 return ret;
731         }
732 #endif
733
734         [EditorBrowsable (EditorBrowsableState.Never)]
735         protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
736                                                              AsyncCallback cb, 
737                                                              object extraData)
738         {
739                 throw new NotImplementedException ();
740         }
741
742         [EditorBrowsable (EditorBrowsableState.Never)]
743         protected void AspCompatEndProcessRequest (IAsyncResult result)
744         {
745                 throw new NotImplementedException ();
746         }
747         
748         [EditorBrowsable (EditorBrowsableState.Advanced)]
749         protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
750         {
751                 return new HtmlTextWriter (tw);
752         }
753
754         [EditorBrowsable (EditorBrowsableState.Never)]
755         public void DesignerInitialize ()
756         {
757                 InitRecursive (null);
758         }
759
760         [EditorBrowsable (EditorBrowsableState.Advanced)]
761         protected virtual NameValueCollection DeterminePostBackMode ()
762         {
763                 if (_context.IsProcessingInclude)
764                         return null;
765
766                 HttpRequest req = Request;
767                 if (req == null)
768                         return null;
769
770                 NameValueCollection coll = null;
771                 if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture))
772                         coll = req.Form;
773                 else
774                         coll = req.QueryString;
775
776                 WebROCollection c = (WebROCollection) coll;
777                 allow_load = !c.GotID;
778                 if (allow_load)
779                         c.ID = GetTypeHashCode ();
780                 else
781                         allow_load = (c.ID == GetTypeHashCode ());
782
783                 if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
784                         return null;
785 #if TARGET_J2EE
786                 if (getFacesContext () != null && _context.Handler != _context.CurrentHandler) {
787                         // check if it is PreviousPage
788                         string prevViewId = coll [PreviousPageID];
789                         if (!String.IsNullOrEmpty (prevViewId)) {
790                                 string appPath = VirtualPathUtility.RemoveTrailingSlash (Request.ApplicationPath);
791                                 prevViewId = prevViewId.Substring (appPath.Length);
792                                 isCrossPagePostBack = String.Compare (prevViewId, getFacesContext ().getExternalContext ().getRequestPathInfo (), StringComparison.OrdinalIgnoreCase) == 0;
793                         }
794                 }
795 #endif
796                 return coll;
797         }
798
799 #if NET_2_0
800         public override Control FindControl (string id) {
801                 return FindControl (id, false);
802         }
803
804         private Control FindControl (string id, bool decode) {
805 #if TARGET_J2EE
806                 if (decode)
807                         id = DecodeNamespace (id);
808 #endif
809                 if (id == ID)
810                         return this;
811                 else
812                         return base.FindControl (id);
813         }
814 #endif
815
816 #if NET_2_0
817         [Obsolete]
818 #endif
819         [EditorBrowsable (EditorBrowsableState.Advanced)]
820         public string GetPostBackClientEvent (Control control, string argument)
821         {
822                 return scriptManager.GetPostBackEventReference (control, argument);
823         }
824
825 #if NET_2_0
826         [Obsolete]
827 #endif
828         [EditorBrowsable (EditorBrowsableState.Advanced)]
829         public string GetPostBackClientHyperlink (Control control, string argument)
830         {
831                 return scriptManager.GetPostBackClientHyperlink (control, argument);
832         }
833
834 #if NET_2_0
835         [Obsolete]
836 #endif
837         [EditorBrowsable (EditorBrowsableState.Advanced)]
838         public string GetPostBackEventReference (Control control)
839         {
840                 return scriptManager.GetPostBackEventReference (control, "");
841         }
842
843 #if NET_2_0
844         [Obsolete]
845 #endif
846         [EditorBrowsable (EditorBrowsableState.Advanced)]
847         public string GetPostBackEventReference (Control control, string argument)
848         {
849                 return scriptManager.GetPostBackEventReference (control, argument);
850         }
851
852         internal void RequiresPostBackScript ()
853         {
854 #if NET_2_0
855                 if (requiresPostBackScript)
856                         return;
857                 ClientScript.RegisterHiddenField (postEventSourceID, String.Empty);
858                 ClientScript.RegisterHiddenField (postEventArgumentID, String.Empty);
859 #endif
860                 requiresPostBackScript = true;
861         }
862
863         [EditorBrowsable (EditorBrowsableState.Never)]
864         public virtual int GetTypeHashCode ()
865         {
866                 return 0;
867         }
868
869 #if NET_2_0
870         [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
871         protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
872         {
873                 if (cacheSettings.Enabled)
874                         InitOutputCache(cacheSettings.Duration,
875                                         cacheSettings.VaryByHeader,
876                                         cacheSettings.VaryByCustom,
877                                         cacheSettings.Location,
878                                         cacheSettings.VaryByParam);
879         }
880 #endif
881
882         [EditorBrowsable (EditorBrowsableState.Never)]
883         protected virtual void InitOutputCache (int duration,
884                                                 string varyByHeader,
885                                                 string varyByCustom,
886                                                 OutputCacheLocation location,
887                                                 string varyByParam)
888         {
889                 HttpCachePolicy cache = Response.Cache;
890                 bool set_vary = false;
891                 HttpContext ctx = Context;
892                 DateTime timestamp = ctx != null ? ctx.Timestamp : DateTime.Now;
893                 
894                 switch (location) {
895                         case OutputCacheLocation.Any:
896                                 cache.SetCacheability (HttpCacheability.Public);
897                                 cache.SetMaxAge (new TimeSpan (0, 0, duration));
898                                 cache.SetLastModified (timestamp);
899                                 set_vary = true;
900                                 break;
901                         case OutputCacheLocation.Client:
902                                 cache.SetCacheability (HttpCacheability.Private);
903                                 cache.SetMaxAge (new TimeSpan (0, 0, duration));
904                                 cache.SetLastModified (timestamp);
905                                 break;
906                         case OutputCacheLocation.Downstream:
907                                 cache.SetCacheability (HttpCacheability.Public);
908                                 cache.SetMaxAge (new TimeSpan (0, 0, duration));
909                                 cache.SetLastModified (timestamp);
910                                 break;
911                         case OutputCacheLocation.Server:                        
912                                 cache.SetCacheability (HttpCacheability.Server);
913                                 set_vary = true;
914                                 break;
915                         case OutputCacheLocation.None:
916                                 break;
917                 }
918
919                 if (set_vary) {
920                         if (varyByCustom != null)
921                                 cache.SetVaryByCustom (varyByCustom);
922
923                         if (varyByParam != null && varyByParam.Length > 0) {
924                                 string[] prms = varyByParam.Split (';');
925                                 foreach (string p in prms)
926                                         cache.VaryByParams [p.Trim ()] = true;
927                                 cache.VaryByParams.IgnoreParams = false;
928                         } else {
929                                 cache.VaryByParams.IgnoreParams = true;
930                         }
931                         
932                         if (varyByHeader != null && varyByHeader.Length > 0) {
933                                 string[] hdrs = varyByHeader.Split (';');
934                                 foreach (string h in hdrs)
935                                         cache.VaryByHeaders [h.Trim ()] = true;
936                         }
937                 }
938                         
939                 cache.Duration = duration;
940                 cache.SetExpires (timestamp.AddSeconds (duration));
941         }
942
943 #if NET_2_0
944         [Obsolete]
945 #else
946         [EditorBrowsable (EditorBrowsableState.Advanced)]
947 #endif
948         public bool IsClientScriptBlockRegistered (string key)
949         {
950                 return scriptManager.IsClientScriptBlockRegistered (key);
951         }
952
953 #if NET_2_0
954         [Obsolete]
955 #else
956         [EditorBrowsable (EditorBrowsableState.Advanced)]
957 #endif
958         public bool IsStartupScriptRegistered (string key)
959         {
960                 return scriptManager.IsStartupScriptRegistered (key);
961         }
962
963         public string MapPath (string virtualPath)
964         {
965                 return Request.MapPath (virtualPath);
966         }
967
968 #if NET_2_0
969         protected internal override void Render (HtmlTextWriter writer) {
970                 if (MaintainScrollPositionOnPostBack) {
971                         ClientScript.RegisterWebFormClientScript ();
972
973                         ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
974                         ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
975
976                         string webForm = IsMultiForm ? theForm + "." : null;
977
978                         StringBuilder script = new StringBuilder ();
979                         script.AppendLine ("<script type=\"text/javascript\">");
980                         script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_START);
981                         script.AppendLine (theForm + ".oldSubmit = " + theForm + ".submit;");
982                         script.AppendLine (theForm + ".submit = function () { " + webForm + "WebForm_SaveScrollPositionSubmit(); }");
983                         script.AppendLine (theForm + ".oldOnSubmit = " + theForm + ".onsubmit;");
984                         script.AppendLine (theForm + ".onsubmit = function () { " + webForm + "WebForm_SaveScrollPositionOnSubmit(); }");
985                         if (IsPostBack) {
986                                 script.AppendLine (theForm + ".oldOnLoad = window.onload;");
987                                 script.AppendLine ("window.onload = function () { " + webForm + "WebForm_RestoreScrollPosition (); };");
988                         }
989                         script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_END);
990                         script.AppendLine ("</script>");
991                         
992                         ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
993                 }
994                 base.Render (writer);
995         }
996 #endif
997
998         private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
999         {
1000 #if ONLY_1_1
1001                 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
1002                 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
1003 #endif
1004                 writer.WriteLine ();
1005                 
1006                 ClientScriptManager.WriteBeginScriptBlock (writer);
1007
1008 #if ONLY_1_1
1009                 RenderClientScriptFormDeclaration (writer, formUniqueID);
1010 #endif
1011                 if (IsMultiForm) {
1012                         writer.WriteLine ("{0}._form = {0};", theForm);
1013                         writer.Write (theForm + ".");
1014                 } else {
1015                         writer.WriteLine ("window._form = {0};", theForm);
1016                 }
1017                 writer.WriteLine ("__doPostBack = function (eventTarget, eventArgument) {");
1018 #if NET_2_0
1019                 writer.WriteLine ("\tif(this._form.onsubmit && this._form.onsubmit() == false) return;");
1020 #else
1021                 writer.WriteLine ("\tif(document.ValidatorOnSubmit && !ValidatorOnSubmit()) return;");
1022 #endif
1023                 writer.WriteLine ("\tthis._form.{0}.value = eventTarget;", postEventSourceID);
1024                 writer.WriteLine ("\tthis._form.{0}.value = eventArgument;", postEventArgumentID);
1025                 writer.WriteLine ("\tthis._form.submit();");
1026                 writer.WriteLine ("}");
1027                 ClientScriptManager.WriteEndScriptBlock (writer);
1028         }
1029
1030         void RenderClientScriptFormDeclaration (HtmlTextWriter writer, string formUniqueID)
1031         {
1032                 writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
1033                 writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
1034                 writer.WriteLine ("\t{0}._instanceVariableName = '{0}';", theForm);
1035 #if TARGET_J2EE
1036                 string serverUrl = EncodeURL (Request.RawUrl);
1037                 writer.WriteLine ("\t{0}.serverURL = {1};", theForm, ClientScriptManager.GetScriptLiteral (serverUrl));
1038                 writer.WriteLine ("\twindow.TARGET_J2EE = true;");
1039                 writer.WriteLine ("\twindow.IsMultiForm = {0};", IsMultiForm ? "true" : "false");
1040 #endif
1041         }
1042
1043         internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
1044         {
1045                 if (renderingForm)
1046                         throw new HttpException ("Only 1 HtmlForm is allowed per page.");
1047
1048                 renderingForm = true;
1049                 writer.WriteLine ();
1050
1051 #if NET_2_0
1052                 ClientScriptManager.WriteBeginScriptBlock (writer);
1053                 RenderClientScriptFormDeclaration (writer, formUniqueID);
1054                 ClientScriptManager.WriteEndScriptBlock (writer);
1055 #endif
1056
1057                 if (handleViewState)
1058 #if TARGET_J2EE
1059                         if (getFacesContext () != null) {
1060                                 javax.faces.application.ViewHandler viewHandler = getFacesContext ().getApplication ().getViewHandler ();
1061                                 javax.faces.context.ResponseWriter oldFacesWriter = SetupResponseWriter (writer);
1062                                 try {
1063                                         viewHandler.writeState (getFacesContext ());
1064                                 }
1065                                 finally {
1066                                         getFacesContext ().setResponseWriter (oldFacesWriter);
1067                                 }
1068                         }
1069 #endif
1070                         scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
1071
1072                 scriptManager.WriteHiddenFields (writer);
1073                 if (requiresPostBackScript) {
1074                         RenderPostBackScript (writer, formUniqueID);
1075                         postBackScriptRendered = true;
1076                 }
1077 #if NET_2_0
1078                 scriptManager.WriteWebFormClientScript (writer);
1079 #endif
1080                 scriptManager.WriteClientScriptBlocks (writer);
1081         }
1082
1083         internal IStateFormatter GetFormatter ()
1084         {
1085                 return new ObjectStateFormatter (this);
1086         }
1087
1088         internal string GetSavedViewState ()
1089         {
1090                 return _savedViewState;
1091         }
1092
1093         internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1094         {
1095 #if NET_2_0
1096                 scriptManager.SaveEventValidationState ();
1097                 scriptManager.WriteExpandoAttributes (writer);
1098 #endif
1099                 scriptManager.WriteHiddenFields (writer);
1100                 if (!postBackScriptRendered && requiresPostBackScript)
1101                         RenderPostBackScript (writer, formUniqueID);
1102 #if NET_2_0
1103                 scriptManager.WriteWebFormClientScript (writer);
1104 #endif
1105
1106                 scriptManager.WriteArrayDeclares (writer);
1107                 scriptManager.WriteStartupScriptBlocks (writer);
1108                 renderingForm = false;
1109                 postBackScriptRendered = false;
1110         }
1111
1112         private void ProcessPostData (NameValueCollection data, bool second)
1113         {
1114                 NameValueCollection requestValues = _requestValueCollection == null ?
1115                         new NameValueCollection () :
1116                         _requestValueCollection;
1117                 
1118                 if (data != null && data.Count > 0) {
1119                         Hashtable used = new Hashtable ();
1120                         foreach (string id in data.AllKeys){
1121                                 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID ||
1122                                     id == ClientScriptManager.EventStateFieldName)
1123                                         continue;
1124                         
1125                                 if (used.ContainsKey (id))
1126                                         continue;
1127
1128                                 used.Add (id, id);
1129
1130                                 Control ctrl = FindControl (id, true);
1131                                 if (ctrl != null){
1132                                         IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1133                                         IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1134
1135                                         if (pbdh == null) {
1136                                                 if (pbeh != null)
1137                                                         RegisterRequiresRaiseEvent (pbeh);
1138                                                 continue;
1139                                         }
1140                 
1141                                         if (pbdh.LoadPostData (id, requestValues) == true) {
1142                                                 if (requiresPostDataChanged == null)
1143                                                         requiresPostDataChanged = new ArrayList ();
1144                                                 requiresPostDataChanged.Add (pbdh);
1145                                         }
1146                                 
1147                                         if (_requiresPostBackCopy != null)
1148                                                 _requiresPostBackCopy.Remove (id);
1149
1150                                 } else if (!second) {
1151                                         if (secondPostData == null)
1152                                                 secondPostData = new NameValueCollection ();
1153                                         secondPostData.Add (id, data [id]);
1154                                 }
1155                         }
1156                 }
1157
1158                 ArrayList list1 = null;
1159                 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1160                         string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1161                         foreach (string id in handlers) {
1162                                 IPostBackDataHandler pbdh = FindControl (id, true) as IPostBackDataHandler;
1163                                 if (pbdh != null) {                     
1164                                         _requiresPostBackCopy.Remove (id);
1165                                         if (pbdh.LoadPostData (id, requestValues)) {
1166                                                 if (requiresPostDataChanged == null)
1167                                                         requiresPostDataChanged = new ArrayList ();
1168         
1169                                                 requiresPostDataChanged.Add (pbdh);
1170                                         }
1171                                 } else if (!second) {
1172                                         if (list1 == null)
1173                                                 list1 = new ArrayList ();
1174                                         list1.Add (id);
1175                                 }
1176                         }
1177                 }
1178                 _requiresPostBackCopy = second ? null : list1;
1179                 if (second)
1180                         secondPostData = null;
1181         }
1182
1183         [EditorBrowsable (EditorBrowsableState.Never)]
1184 #if NET_2_0
1185         public virtual void ProcessRequest (HttpContext context)
1186 #else
1187         public void ProcessRequest (HttpContext context)
1188 #endif
1189         {
1190 #if NET_2_0
1191                 _lifeCycle = PageLifeCycle.Unknown;
1192 #endif
1193                 SetContext (context);
1194                 
1195                 if (clientTarget != null)
1196                         Request.ClientTarget = clientTarget;
1197
1198                 WireupAutomaticEvents ();
1199                 //-- Control execution lifecycle in the docs
1200
1201                 // Save culture information because it can be modified in FrameworkInitialize()
1202                 _appCulture = Thread.CurrentThread.CurrentCulture;
1203                 _appUICulture = Thread.CurrentThread.CurrentUICulture;
1204                 FrameworkInitialize ();
1205                 context.ErrorPage = _errorPage;
1206
1207                 try {
1208                         InternalProcessRequest ();
1209                 }
1210 #if TARGET_J2EE
1211                 catch (Exception ex) {
1212                         HandleException (ex);
1213                         throw;
1214                 }
1215 #else
1216                 catch (ThreadAbortException) {
1217                         // Do nothing, just ignore it by now.
1218                 } catch (Exception e) {
1219                         ProcessException (e);
1220                         throw;
1221                 }
1222                 finally {
1223                         ProcessUnload ();
1224                 }
1225 #endif
1226         }
1227
1228         void ProcessException (Exception ex) {
1229                 _context.AddError (ex); // OnError might access LastError
1230                 OnError (EventArgs.Empty);
1231                 _context.ClearError (ex);
1232                 // We want to remove that error, as we're rethrowing to stop
1233                 // further processing.
1234                 Trace.Warn ("Unhandled Exception", ex.ToString (), ex);
1235         }
1236
1237         void ProcessUnload () {
1238                         try {
1239 #if NET_2_0
1240                                 _lifeCycle = PageLifeCycle.Unload;
1241 #endif
1242                                 RenderTrace ();
1243                                 UnloadRecursive (true);
1244 #if NET_2_0
1245                                 _lifeCycle = PageLifeCycle.End;
1246 #endif
1247                         } catch {}
1248 #if TARGET_J2EE
1249                         if (getFacesContext () != null) {
1250                                 if(IsCrossPagePostBack)
1251                                         _context.Items [CrossPagePostBack] = this;
1252                         }
1253 #endif
1254                         if (Thread.CurrentThread.CurrentCulture.Equals (_appCulture) == false)
1255                                 Thread.CurrentThread.CurrentCulture = _appCulture;
1256
1257                         if (Thread.CurrentThread.CurrentUICulture.Equals (_appUICulture) == false)
1258                                 Thread.CurrentThread.CurrentUICulture = _appUICulture;
1259                         
1260                         _appCulture = null;
1261                         _appUICulture = null;
1262         }
1263         
1264 #if NET_2_0
1265         delegate void ProcessRequestDelegate (HttpContext context);
1266
1267         private sealed class DummyAsyncResult : IAsyncResult
1268         {
1269                 readonly object state;
1270                 readonly WaitHandle asyncWaitHandle;
1271                 readonly bool completedSynchronously;
1272                 readonly bool isCompleted;
1273
1274                 public DummyAsyncResult (bool isCompleted, bool completedSynchronously, object state) 
1275                 {
1276                         this.isCompleted = isCompleted;
1277                         this.completedSynchronously = completedSynchronously;
1278                         this.state = state;
1279                         if (isCompleted) {
1280                                 asyncWaitHandle = new ManualResetEvent (true);
1281                         }
1282                         else {
1283                                 asyncWaitHandle = new ManualResetEvent (false);
1284                         }
1285                 }
1286
1287                 #region IAsyncResult Members
1288
1289                 public object AsyncState {
1290                         get { return state; }
1291                 }
1292
1293                 public WaitHandle AsyncWaitHandle {
1294                         get { return asyncWaitHandle; }
1295                 }
1296
1297                 public bool CompletedSynchronously {
1298                         get { return completedSynchronously; }
1299                 }
1300
1301                 public bool IsCompleted {
1302                         get { return isCompleted; }
1303                 }
1304
1305                 #endregion
1306         }
1307
1308         protected IAsyncResult AsyncPageBeginProcessRequest (HttpContext context, AsyncCallback callback, object extraData) 
1309         {
1310                 ProcessRequest (context);
1311                 DummyAsyncResult asyncResult = new DummyAsyncResult (true, true, extraData);
1312
1313                 if (callback != null) {
1314                         callback (asyncResult);
1315                 }
1316                 
1317                 return asyncResult;
1318         }
1319
1320         protected void AsyncPageEndProcessRequest (IAsyncResult result) 
1321         {
1322         }
1323 #endif
1324
1325         void InternalProcessRequest ()
1326         {
1327                 _requestValueCollection = this.DeterminePostBackMode();
1328                 
1329 #if NET_2_0
1330
1331                 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1332                 if (_requestValueCollection != null) {
1333                         if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1334                                 _doLoadPreviousPage = true;
1335                         }
1336                         else {
1337                                 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1338                                 // LAMESPEC: on Callback IsPostBack is set to false, but true.
1339                                 //isPostBack = !isCallback;
1340                                 isPostBack = true;
1341                         }
1342                         string lastFocus = _requestValueCollection [LastFocusID];
1343                         if (!String.IsNullOrEmpty (lastFocus)) {
1344                                 _focusedControlID = UniqueID2ClientID (lastFocus);
1345                         }
1346                 }
1347                 
1348                 if (!isCrossPagePostBack) {
1349                         if (_context.PreviousHandler is Page) {
1350                                 previousPage = (Page) _context.PreviousHandler;
1351                         }
1352                 }
1353
1354                 _lifeCycle = PageLifeCycle.PreInit;
1355                 Trace.Write ("aspx.page", "Begin PreInit");
1356                 OnPreInit (EventArgs.Empty);
1357                 Trace.Write ("aspx.page", "End PreInit");
1358
1359                 InitializeTheme ();
1360                 ApplyMasterPage ();
1361                 _lifeCycle = PageLifeCycle.Init;
1362 #endif
1363                 Trace.Write ("aspx.page", "Begin Init");
1364                 InitRecursive (null);
1365                 Trace.Write ("aspx.page", "End Init");
1366
1367 #if NET_2_0
1368                 _lifeCycle = PageLifeCycle.InitComplete;
1369                 Trace.Write ("aspx.page", "Begin InitComplete");
1370                 OnInitComplete (EventArgs.Empty);
1371                 Trace.Write ("aspx.page", "End InitComplete");
1372 #endif
1373                         
1374                 renderingForm = false;  
1375
1376 #if TARGET_J2EE
1377                 if (getFacesContext () != null)
1378                         if (IsPostBack || IsCallback)
1379                                 return;
1380 #endif
1381
1382                 RestorePageState ();
1383                 ProcessPostData ();
1384                 ProcessRaiseChangedEvents ();
1385                 ProcessRaisePostBackEvents ();
1386                 if (ProcessLoadComplete ())
1387                         return;
1388 #if TARGET_J2EE
1389                 if (getFacesContext () != null)
1390                         return;
1391 #endif
1392                 RenderPage ();
1393         }
1394
1395         void RestorePageState () {
1396 #if NET_2_0
1397                 if (IsPostBack || IsCallback) {
1398 #else
1399                 if (IsPostBack) {
1400 #endif
1401 #if NET_2_0
1402                         _lifeCycle = PageLifeCycle.PreLoad;
1403                         if (_requestValueCollection != null)
1404                                 scriptManager.RestoreEventValidationState (
1405                                         _requestValueCollection [ClientScriptManager.EventStateFieldName]);
1406 #endif
1407                         Trace.Write ("aspx.page", "Begin LoadViewState");
1408                         LoadPageViewState ();
1409                         Trace.Write ("aspx.page", "End LoadViewState");
1410                 }
1411         }
1412
1413         void ProcessPostData () {
1414
1415 #if NET_2_0
1416 //#if TARGET_J2EE
1417 //        if (!IsGetBack)
1418 //#endif
1419                 if (IsPostBack || IsCallback) {
1420 #else
1421                 if (IsPostBack) {
1422 #endif
1423                         Trace.Write ("aspx.page", "Begin ProcessPostData");
1424                         ProcessPostData (_requestValueCollection, false);
1425                         Trace.Write ("aspx.page", "End ProcessPostData");
1426                 }
1427
1428                 ProcessLoad ();
1429
1430 #if NET_2_0
1431 //#if TARGET_J2EE
1432 //        if (IsGetBack)
1433 //            RestoreValidatorsState ();
1434 //        else
1435 //#endif
1436                 if (IsPostBack || IsCallback) {
1437 #else
1438                 if (IsPostBack) {
1439 #endif
1440 #if NET_2_0
1441                         _lifeCycle = PageLifeCycle.ControlEvents;
1442 #endif
1443                         Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1444                         ProcessPostData (secondPostData, true);
1445                         Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1446                 }
1447         }
1448
1449         void ProcessLoad () { 
1450 #if NET_2_0
1451                 Trace.Write ("aspx.page", "Begin PreLoad");
1452                 OnPreLoad (EventArgs.Empty);
1453                 Trace.Write ("aspx.page", "End PreLoad");
1454                 _lifeCycle = PageLifeCycle.Load;
1455 #endif
1456
1457                 Trace.Write ("aspx.page", "Begin Load");
1458                 LoadRecursive ();
1459                 Trace.Write ("aspx.page", "End Load");
1460         }
1461
1462         void ProcessRaiseChangedEvents () {
1463
1464 #if NET_2_0
1465 //#if TARGET_J2EE
1466 //        if (!IsGetBack)
1467 //#endif
1468                 if (IsPostBack || IsCallback) {
1469 #else
1470                 if (IsPostBack) {
1471 #endif
1472                         Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1473                         RaiseChangedEvents ();
1474                         Trace.Write ("aspx.page", "End Raise ChangedEvents");
1475                 }
1476         }
1477
1478         void ProcessRaisePostBackEvents () {
1479
1480 #if NET_2_0
1481 //#if TARGET_J2EE
1482 //        if (!IsGetBack)
1483 //#endif
1484                 if (IsPostBack || IsCallback) {
1485 #else
1486                 if (IsPostBack) {
1487 #endif
1488                         Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1489                         RaisePostBackEvents ();
1490                         Trace.Write ("aspx.page", "End Raise PostBackEvent");
1491                 }
1492         }
1493
1494         bool ProcessLoadComplete() {
1495                 
1496 #if NET_2_0
1497                 _lifeCycle = PageLifeCycle.LoadComplete;
1498                 Trace.Write ("aspx.page", "Begin LoadComplete");
1499                 OnLoadComplete (EventArgs.Empty);
1500                 Trace.Write ("aspx.page", "End LoadComplete");
1501
1502                 if (IsCrossPagePostBack)
1503                         return true;
1504
1505                 if (IsCallback) {
1506 #if TARGET_J2EE
1507                         if (getFacesContext () != null) {
1508                                 _callbackTarget = GetCallbackTarget ();
1509                                 ProcessRaiseCallbackEvent (_callbackTarget, ref _callbackEventError);
1510                                 return true;
1511                         }
1512 #endif
1513                         string result = ProcessCallbackData ();
1514                         HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);
1515                         callbackOutput.Write (result);
1516                         callbackOutput.Flush ();
1517                         return true;
1518                 }
1519
1520                 _lifeCycle = PageLifeCycle.PreRender;
1521 #endif
1522                 
1523                 Trace.Write ("aspx.page", "Begin PreRender");
1524                 PreRenderRecursiveInternal ();
1525                 Trace.Write ("aspx.page", "End PreRender");
1526                 
1527 #if NET_2_0
1528                 ExecuteRegisteredAsyncTasks ();
1529
1530                 _lifeCycle = PageLifeCycle.PreRenderComplete;
1531                 Trace.Write ("aspx.page", "Begin PreRenderComplete");
1532                 OnPreRenderComplete (EventArgs.Empty);
1533                 Trace.Write ("aspx.page", "End PreRenderComplete");
1534 #endif
1535
1536                 Trace.Write ("aspx.page", "Begin SaveViewState");
1537                 SavePageViewState ();
1538                 Trace.Write ("aspx.page", "End SaveViewState");
1539                 
1540 #if NET_2_0
1541                 _lifeCycle = PageLifeCycle.SaveStateComplete;
1542                 Trace.Write ("aspx.page", "Begin SaveStateComplete");
1543                 OnSaveStateComplete (EventArgs.Empty);
1544                 Trace.Write ("aspx.page", "End SaveStateComplete");
1545 #endif // NET_2_0
1546                 return false;
1547         }
1548
1549         internal void RenderPage () {
1550 #if NET_2_0
1551                 _lifeCycle = PageLifeCycle.Render;
1552                 scriptManager.ResetEventValidationState ();
1553 #endif
1554                 
1555                 //--
1556                 Trace.Write ("aspx.page", "Begin Render");
1557                 HtmlTextWriter output = new HtmlTextWriter (Response.Output);
1558 #if TARGET_J2EE
1559                 if (getFacesContext () != null)
1560                         SetupResponseWriter (output);
1561 #endif
1562                 RenderControl (output);
1563                 Trace.Write ("aspx.page", "End Render");
1564         }
1565
1566         void SetContext (HttpContext context) {
1567                 _context = context;
1568
1569                 _application = context.Application;
1570                 _response = context.Response;
1571                 _request = context.Request;
1572                 _cache = context.Cache;
1573         }
1574
1575         private void RenderTrace ()
1576         {
1577                 TraceManager traceManager = HttpRuntime.TraceManager;
1578
1579                 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1580                         return;
1581                 
1582                 Trace.SaveData ();
1583
1584                 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput) 
1585                         return;
1586
1587                 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1588                         HtmlTextWriter output = new HtmlTextWriter (Response.Output);
1589                         Trace.Render (output);
1590                 }
1591         }
1592         
1593 #if NET_2_0
1594         bool CheckForValidationSupport (Control targetControl)
1595         {
1596                 if (targetControl == null)
1597                         return false;
1598                 Type type = targetControl.GetType ();
1599                 object[] attributes = type.GetCustomAttributes (false);
1600                 foreach (object attr in attributes)
1601                         if (attr is SupportsEventValidationAttribute)
1602                                 return true;
1603                 return false;
1604         }
1605 #endif
1606         
1607         void RaisePostBackEvents ()
1608         {
1609 #if NET_2_0
1610                 Control targetControl;
1611 #endif
1612                 if (requiresRaiseEvent != null) {
1613                         RaisePostBackEvent (requiresRaiseEvent, null);
1614                         return;
1615                 }
1616
1617                 NameValueCollection postdata = _requestValueCollection;
1618                 if (postdata == null)
1619                         return;
1620
1621                 string eventTarget = postdata [postEventSourceID];
1622                 if (eventTarget == null || eventTarget.Length == 0) {
1623                         Validate ();
1624                         return;
1625                 }
1626
1627 #if NET_2_0
1628                 targetControl = FindControl (eventTarget, true);
1629                 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1630 #else
1631                 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
1632 #endif
1633                         
1634                 if (target == null)
1635                         return;
1636
1637                 string eventArgument = postdata [postEventArgumentID];
1638                 RaisePostBackEvent (target, eventArgument);
1639         }
1640
1641         internal void RaiseChangedEvents ()
1642         {
1643                 if (requiresPostDataChanged == null)
1644                         return;
1645
1646                 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1647                         ipdh.RaisePostDataChangedEvent ();
1648
1649                 requiresPostDataChanged = null;
1650         }
1651
1652         [EditorBrowsable (EditorBrowsableState.Advanced)]
1653         protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1654         {
1655 #if NET_2_0
1656                 Control targetControl = sourceControl as Control;
1657                 if (targetControl != null && CheckForValidationSupport (targetControl))
1658                         scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
1659 #endif
1660                 sourceControl.RaisePostBackEvent (eventArgument);
1661         }
1662         
1663 #if NET_2_0
1664         [Obsolete]
1665 #endif
1666         [EditorBrowsable (EditorBrowsableState.Advanced)]
1667         public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1668         {
1669                 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1670         }
1671
1672 #if NET_2_0
1673         [Obsolete]
1674 #endif
1675         [EditorBrowsable (EditorBrowsableState.Advanced)]
1676         public virtual void RegisterClientScriptBlock (string key, string script)
1677         {
1678                 scriptManager.RegisterClientScriptBlock (key, script);
1679         }
1680
1681 #if NET_2_0
1682         [Obsolete]
1683 #endif
1684         [EditorBrowsable (EditorBrowsableState.Advanced)]
1685         public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1686         {
1687                 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1688         }
1689
1690         [MonoTODO("Not implemented, Used in HtmlForm")]
1691         internal void RegisterClientScriptFile (string a, string b, string c)
1692         {
1693                 throw new NotImplementedException ();
1694         }
1695
1696 #if NET_2_0
1697         [Obsolete]
1698 #endif
1699         [EditorBrowsable (EditorBrowsableState.Advanced)]
1700         public void RegisterOnSubmitStatement (string key, string script)
1701         {
1702                 scriptManager.RegisterOnSubmitStatement (key, script);
1703         }
1704
1705         internal string GetSubmitStatements ()
1706         {
1707                 return scriptManager.WriteSubmitStatements ();
1708         }
1709
1710         [EditorBrowsable (EditorBrowsableState.Advanced)]
1711         public void RegisterRequiresPostBack (Control control)
1712         {
1713 #if NET_2_0
1714                 if (!(control is IPostBackDataHandler))
1715                         throw new HttpException ("The control to register does not implement the IPostBackDataHandler interface.");
1716 #endif
1717                 
1718                 if (_requiresPostBack == null)
1719                         _requiresPostBack = new ArrayList ();
1720
1721                 if (_requiresPostBack.Contains (control.UniqueID))
1722                         return;
1723
1724                 _requiresPostBack.Add (control.UniqueID);
1725         }
1726
1727         [EditorBrowsable (EditorBrowsableState.Advanced)]
1728         public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1729         {
1730                 requiresRaiseEvent = control;
1731         }
1732
1733 #if NET_2_0
1734         [Obsolete]
1735 #endif
1736         [EditorBrowsable (EditorBrowsableState.Advanced)]
1737         public virtual void RegisterStartupScript (string key, string script)
1738         {
1739                 scriptManager.RegisterStartupScript (key, script);
1740         }
1741
1742         [EditorBrowsable (EditorBrowsableState.Advanced)]
1743         public void RegisterViewStateHandler ()
1744         {
1745                 handleViewState = true;
1746         }
1747
1748         [EditorBrowsable (EditorBrowsableState.Advanced)]
1749         protected virtual void SavePageStateToPersistenceMedium (object viewState)
1750         {
1751                 PageStatePersister persister = this.PageStatePersister;
1752                 if (persister == null)
1753                         return;
1754                 Pair pair = viewState as Pair;
1755                 if (pair != null) {
1756                         persister.ViewState = pair.First;
1757                         persister.ControlState = pair.Second;
1758                 } else
1759                         persister.ViewState = viewState;
1760                 persister.Save ();
1761         }
1762
1763         internal string RawViewState {
1764                 get {
1765                         NameValueCollection postdata = _requestValueCollection;
1766                         string view_state;
1767                         if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1768                                 return null;
1769
1770                         if (view_state == "")
1771                                 return null;
1772                         return view_state;
1773                 }
1774                 set { _savedViewState = value; }
1775         }
1776
1777 #if NET_2_0
1778         protected virtual 
1779 #else
1780         internal
1781 #endif
1782         PageStatePersister PageStatePersister {
1783                 get {
1784                         if (page_state_persister == null)
1785 #if TARGET_J2EE
1786                                 if (getFacesContext () != null)
1787                                         return new FacesPageStatePersister (this);
1788                                 else
1789 #endif
1790                                 page_state_persister = new HiddenFieldPageStatePersister (this);
1791                         return page_state_persister;
1792                 }
1793         }
1794         
1795         [EditorBrowsable (EditorBrowsableState.Advanced)]
1796         protected virtual object LoadPageStateFromPersistenceMedium ()
1797         {
1798                 PageStatePersister persister = this.PageStatePersister;
1799                 if (persister == null)
1800                         return null;
1801                 persister.Load ();
1802                 return new Pair (persister.ViewState, persister.ControlState);
1803         }
1804
1805         internal void LoadPageViewState()
1806         {
1807                 Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
1808                 if (sState != null) {
1809                         if (allow_load) {
1810 #if NET_2_0
1811                                 LoadPageControlState (sState.Second);
1812 #endif
1813                                 Pair vsr = sState.First as Pair;
1814                                 if (vsr != null) {
1815                                         LoadViewStateRecursive (vsr.First);
1816                                         _requiresPostBackCopy = vsr.Second as ArrayList;
1817                                 }
1818                         }
1819                 }
1820         }
1821
1822         internal void SavePageViewState ()
1823         {
1824                 if (!handleViewState)
1825                         return;
1826
1827 #if NET_2_0
1828                 object controlState = SavePageControlState ();
1829 #endif
1830
1831                 object viewState = SaveViewStateRecursive ();
1832                 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1833                 Pair vsr = null;
1834
1835                 if (viewState != null || reqPostback != null)
1836                         vsr = new Pair (viewState, reqPostback);
1837                 Pair pair = new Pair ();
1838
1839                 pair.First = vsr;
1840 #if NET_2_0
1841                 pair.Second = controlState;
1842 #else
1843                 pair.Second = null;
1844 #endif
1845                 if (pair.First == null && pair.Second == null)
1846                         SavePageStateToPersistenceMedium (null);
1847                 else
1848                         SavePageStateToPersistenceMedium (pair);                
1849
1850         }
1851
1852         public virtual void Validate ()
1853         {
1854                 is_validated = true;
1855                 ValidateCollection (_validators);
1856         }
1857
1858 #if NET_2_0
1859         internal bool AreValidatorsUplevel () {
1860                 return AreValidatorsUplevel (String.Empty);
1861         }
1862
1863         internal bool AreValidatorsUplevel (string valGroup)
1864 #else
1865         internal virtual bool AreValidatorsUplevel ()
1866 #endif
1867         {
1868                 bool uplevel = false;
1869
1870                 foreach (IValidator v in Validators) {
1871                         BaseValidator bv = v as BaseValidator;
1872                         if (bv == null) continue;
1873
1874 #if NET_2_0
1875                         if (valGroup != bv.ValidationGroup)
1876                                 continue;
1877 #endif
1878                         if (bv.GetRenderUplevel()) {
1879                                 uplevel = true;
1880                                 break;
1881                         }
1882                 }
1883
1884                 return uplevel;
1885         }
1886
1887         bool ValidateCollection (ValidatorCollection validators)
1888         {
1889 #if NET_2_0
1890                 if (!_eventValidation)
1891                         return true;
1892 #endif
1893
1894                 if (validators == null || validators.Count == 0)
1895                         return true;
1896
1897                 bool all_valid = true;
1898                 foreach (IValidator v in validators){
1899                         v.Validate ();
1900                         if (v.IsValid == false)
1901                                 all_valid = false;
1902                 }
1903
1904                 return all_valid;
1905         }
1906
1907         [EditorBrowsable (EditorBrowsableState.Advanced)]
1908         public virtual void VerifyRenderingInServerForm (Control control)
1909         {
1910                 if (Context == null)
1911                         return;
1912 #if NET_2_0
1913                 if (IsCallback)
1914                         return;
1915 #endif
1916                 if (!renderingForm)
1917                         throw new HttpException ("Control '" +
1918                                                  control.ClientID +
1919                                                  "' of type '" +
1920                                                  control.GetType ().Name +
1921                                                  "' must be placed inside a form tag with runat=server.");
1922         }
1923
1924         protected override void FrameworkInitialize ()
1925         {
1926                 base.FrameworkInitialize ();
1927 #if NET_2_0
1928                 InitializeStyleSheet ();
1929 #endif
1930         }
1931
1932         #endregion
1933         
1934         #if NET_2_0
1935         public
1936         #else
1937         internal
1938         #endif
1939                 ClientScriptManager ClientScript {
1940                 get { return scriptManager; }
1941         }
1942         
1943         #if NET_2_0
1944         
1945         static readonly object InitCompleteEvent = new object ();
1946         static readonly object LoadCompleteEvent = new object ();
1947         static readonly object PreInitEvent = new object ();
1948         static readonly object PreLoadEvent = new object ();
1949         static readonly object PreRenderCompleteEvent = new object ();
1950         static readonly object SaveStateCompleteEvent = new object ();
1951         int event_mask;
1952         const int initcomplete_mask = 1;
1953         const int loadcomplete_mask = 1 << 1;
1954         const int preinit_mask = 1 << 2;
1955         const int preload_mask = 1 << 3;
1956         const int prerendercomplete_mask = 1 << 4;
1957         const int savestatecomplete_mask = 1 << 5;
1958         
1959         [EditorBrowsable (EditorBrowsableState.Advanced)]
1960         public event EventHandler InitComplete {
1961                 add {
1962                         event_mask |= initcomplete_mask;
1963                         Events.AddHandler (InitCompleteEvent, value);
1964                 }
1965                 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1966         }
1967         
1968         [EditorBrowsable (EditorBrowsableState.Advanced)]
1969         public event EventHandler LoadComplete {
1970                 add {
1971                         event_mask |= loadcomplete_mask;
1972                         Events.AddHandler (LoadCompleteEvent, value);
1973                 }
1974                 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1975         }
1976         
1977         public event EventHandler PreInit {
1978                 add {
1979                         event_mask |= preinit_mask;
1980                         Events.AddHandler (PreInitEvent, value);
1981                 }
1982                 remove { Events.RemoveHandler (PreInitEvent, value); }
1983         }
1984         
1985         [EditorBrowsable (EditorBrowsableState.Advanced)]
1986         public event EventHandler PreLoad {
1987                 add {
1988                         event_mask |= preload_mask;
1989                         Events.AddHandler (PreLoadEvent, value);
1990                 }
1991                 remove { Events.RemoveHandler (PreLoadEvent, value); }
1992         }
1993         
1994         [EditorBrowsable (EditorBrowsableState.Advanced)]
1995         public event EventHandler PreRenderComplete {
1996                 add {
1997                         event_mask |= prerendercomplete_mask;
1998                         Events.AddHandler (PreRenderCompleteEvent, value);
1999                 }
2000                 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
2001         }
2002         
2003         [EditorBrowsable (EditorBrowsableState.Advanced)]
2004         public event EventHandler SaveStateComplete {
2005                 add {
2006                         event_mask |= savestatecomplete_mask;
2007                         Events.AddHandler (SaveStateCompleteEvent, value);
2008                 }
2009                 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
2010         }
2011         
2012         protected virtual void OnInitComplete (EventArgs e)
2013         {
2014                 if ((event_mask & initcomplete_mask) != 0) {
2015                         EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
2016                         if (eh != null) eh (this, e);
2017                 }
2018         }
2019         
2020         protected virtual void OnLoadComplete (EventArgs e)
2021         {
2022                 if ((event_mask & loadcomplete_mask) != 0) {
2023                         EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
2024                         if (eh != null) eh (this, e);
2025                 }
2026         }
2027         
2028         protected virtual void OnPreInit (EventArgs e)
2029         {
2030                 if ((event_mask & preinit_mask) != 0) {
2031                         EventHandler eh = (EventHandler) (Events [PreInitEvent]);
2032                         if (eh != null) eh (this, e);
2033                 }
2034         }
2035         
2036         protected virtual void OnPreLoad (EventArgs e)
2037         {
2038                 if ((event_mask & preload_mask) != 0) {
2039                         EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
2040                         if (eh != null) eh (this, e);
2041                 }
2042         }
2043         
2044         protected virtual void OnPreRenderComplete (EventArgs e)
2045         {
2046                 if ((event_mask & prerendercomplete_mask) != 0) {
2047                         EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
2048                         if (eh != null) eh (this, e);
2049                 }
2050
2051                 if (Form == null)
2052                         return;
2053                 if (!Form.DetermineRenderUplevel ())
2054                         return;
2055
2056                 string defaultButtonId = Form.DefaultButton;
2057                 /* figure out if we have some control we're going to focus */
2058                 if (String.IsNullOrEmpty (_focusedControlID)) {
2059                         _focusedControlID = Form.DefaultFocus;
2060                         if (String.IsNullOrEmpty (_focusedControlID))
2061                                 _focusedControlID = defaultButtonId;
2062                 }
2063
2064                 if (!String.IsNullOrEmpty (_focusedControlID)) {
2065                         ClientScript.RegisterWebFormClientScript ();
2066                         ClientScript.RegisterStartupScript (
2067                                 "HtmlForm-DefaultButton-StartupScript",
2068                                 String.Format (
2069                                         "<script type=\"text/javascript\">\n{0}\nWebForm_AutoFocus('{1}');\n{2}\n</script>\n",
2070                                         ClientScriptManager.SCRIPT_BLOCK_START,
2071                                         _focusedControlID,
2072                                         ClientScriptManager.SCRIPT_BLOCK_END)
2073                         );
2074                 }
2075                 
2076                 if (Form.SubmitDisabledControls && _hasEnabledControlArray) {
2077                         ClientScript.RegisterWebFormClientScript ();
2078                         ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
2079                                                                 "WebForm_ReEnableControls(this);");
2080                 }
2081         }
2082
2083         internal void RegisterEnabledControl (Control control)
2084         {
2085                 if (Form == null || !Page.Form.SubmitDisabledControls || !Page.Form.DetermineRenderUplevel ())
2086                         return;
2087                 _hasEnabledControlArray = true;
2088                 Page.ClientScript.RegisterArrayDeclaration (EnabledControlArrayID, String.Format ("'{0}'", control.ClientID));
2089         }
2090         
2091         protected virtual void OnSaveStateComplete (EventArgs e)
2092         {
2093                 if ((event_mask & savestatecomplete_mask) != 0) {
2094                         EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
2095                         if (eh != null) eh (this, e);
2096                 }
2097         }
2098         
2099         public HtmlForm Form {
2100                 get { return _form; }
2101         }
2102         
2103         internal void RegisterForm (HtmlForm form)
2104         {
2105                 _form = form;
2106         }
2107         
2108         [BrowsableAttribute (false)]
2109         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2110         public Page PreviousPage {
2111                 get {
2112                         if (_doLoadPreviousPage) {
2113                                 _doLoadPreviousPage = false;
2114                                 LoadPreviousPageReference ();
2115                         }
2116                         return previousPage;
2117                 }
2118         }
2119
2120         
2121         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2122         [BrowsableAttribute (false)]
2123         public bool IsCallback {
2124                 get { return isCallback; }
2125         }
2126         
2127         [BrowsableAttribute (false)]
2128         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2129         public bool IsCrossPagePostBack {
2130                 get { return isCrossPagePostBack; }
2131         }
2132
2133         public new virtual char IdSeparator {
2134                 get {
2135                         //TODO: why override?
2136                         return base.IdSeparator;
2137                 }
2138         }
2139         
2140         string ProcessCallbackData ()
2141         {
2142                 ICallbackEventHandler target = GetCallbackTarget ();
2143                 string callbackEventError = String.Empty;
2144                 ProcessRaiseCallbackEvent (target, ref callbackEventError);
2145                 return ProcessGetCallbackResult (target, callbackEventError);
2146         }
2147
2148         ICallbackEventHandler GetCallbackTarget () {
2149                 string callbackTarget = _requestValueCollection [CallbackSourceID];
2150                 if (callbackTarget == null || callbackTarget.Length == 0)
2151                         throw new HttpException ("Callback target not provided.");
2152
2153                 Control targetControl = FindControl (callbackTarget, true);
2154                 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
2155                 if (target == null)
2156                         throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
2157                 return target;
2158         }
2159
2160         void ProcessRaiseCallbackEvent (ICallbackEventHandler target, ref string callbackEventError) {
2161                 string callbackArgument = _requestValueCollection [CallbackArgumentID];
2162
2163                 try {
2164                         target.RaiseCallbackEvent (callbackArgument);
2165                 }
2166                 catch (Exception ex) {
2167                         callbackEventError = String.Format ("e{0}", ex.Message);
2168                 }
2169         }
2170
2171         string ProcessGetCallbackResult (ICallbackEventHandler target, string callbackEventError) {
2172                 string callBackResult;
2173                 try {
2174                         callBackResult = target.GetCallbackResult ();
2175                 }
2176                 catch (Exception ex) {
2177                         return String.Format ("e{0}", ex.Message);
2178                 }
2179                 
2180                 string eventValidation = ClientScript.GetEventValidationStateFormatted ();
2181                 return String.Format ("{0}{1}|{2}{3}", callbackEventError, eventValidation == null ? 0 : eventValidation.Length, eventValidation, callBackResult);
2182         }
2183
2184         [BrowsableAttribute (false)]
2185         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2186         public HtmlHead Header {
2187                 get { return htmlHeader; }
2188         }
2189         
2190         internal void SetHeader (HtmlHead header)
2191         {
2192                 htmlHeader = header;
2193                 if (_title != null) {
2194                         htmlHeader.Title = _title;
2195                         _title = null;
2196                 }
2197         }
2198
2199         protected bool AsyncMode {
2200                 get { return asyncMode; }
2201                 set { asyncMode = value; }
2202         }
2203
2204         public TimeSpan AsyncTimeout {
2205                 get { return asyncTimeout; }
2206                 set { asyncTimeout = value; }
2207         }
2208
2209         public bool IsAsync {
2210                 get { return AsyncMode; }
2211         }
2212         
2213         [MonoTODO ("Not Implemented")]
2214         protected internal virtual string UniqueFilePathSuffix {
2215                 get {
2216                         throw new NotImplementedException ();
2217                 }
2218         }
2219
2220         [MonoTODO ("Not Implemented")]
2221         public int MaxPageStateFieldLength {
2222                 get {
2223                         throw new NotImplementedException ();
2224                 }
2225                 set {
2226                         throw new NotImplementedException ();
2227                 }
2228         }
2229
2230         public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
2231         {
2232                 AddOnPreRenderCompleteAsync (beginHandler, endHandler, null);
2233         }
2234
2235         public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
2236         {
2237                 if (!IsAsync) {
2238                         throw new InvalidOperationException ("AddOnPreRenderCompleteAsync called and Page.IsAsync == false");
2239                 }
2240
2241                 if (_lifeCycle >= PageLifeCycle.PreRender) {
2242                         throw new InvalidOperationException ("AddOnPreRenderCompleteAsync can only be called before PreRender.");
2243                 }
2244
2245                 if (beginHandler == null) {
2246                         throw new ArgumentNullException ("beginHandler");
2247                 }
2248
2249                 if (endHandler == null) {
2250                         throw new ArgumentNullException ("endHandler");
2251                 }
2252
2253                 RegisterAsyncTask (new PageAsyncTask (beginHandler, endHandler, null, state, false));
2254         }
2255
2256         private List<PageAsyncTask> ParallelTasks {
2257                 get {
2258                         if (parallelTasks == null) {
2259                                 parallelTasks = new List<PageAsyncTask>();
2260                         }
2261                         return parallelTasks;
2262                 }
2263         }
2264
2265         private List<PageAsyncTask> SerialTasks {
2266                 get {
2267                         if (serialTasks == null) {
2268                                 serialTasks = new List<PageAsyncTask> ();
2269                         }
2270                         return serialTasks;
2271                 }
2272         }
2273
2274         public void RegisterAsyncTask (PageAsyncTask task) 
2275         {
2276                 if (task == null) {
2277                         throw new ArgumentNullException ("task");
2278                 }
2279
2280                 if (task.ExecuteInParallel) {
2281                         ParallelTasks.Add (task);
2282                 }
2283                 else {
2284                         SerialTasks.Add (task);
2285                 }
2286         }
2287
2288         public void ExecuteRegisteredAsyncTasks ()
2289         {
2290                 if ((parallelTasks == null || parallelTasks.Count == 0) &&
2291                         (serialTasks == null || serialTasks.Count == 0)){
2292                         return;
2293                 }
2294
2295                 if (parallelTasks != null) {
2296                         DateTime startExecution = DateTime.Now;
2297                         List<PageAsyncTask> localParallelTasks = parallelTasks;
2298                         parallelTasks = null; // Shouldn't execute tasks twice
2299                         List<IAsyncResult> asyncResults = new List<IAsyncResult>();
2300                         foreach (PageAsyncTask parallelTask in localParallelTasks) {
2301                                 IAsyncResult result = parallelTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), parallelTask.State);
2302                                 if (result.CompletedSynchronously) {
2303                                         parallelTask.EndHandler (result);
2304                                 }
2305                                 else {
2306                                         asyncResults.Add (result);
2307                                 }
2308                         }
2309
2310                         if (asyncResults.Count > 0) {
2311 #if TARGET_JVM
2312                                 TimeSpan timeout = AsyncTimeout;
2313                                 long t1 = DateTime.Now.Ticks;
2314                                 bool signalled = true;
2315                                 for (int i = 0; i < asyncResults.Count; i++) {
2316                                         if (asyncResults [i].IsCompleted)
2317                                                 continue;
2318
2319                                         if (signalled)
2320                                                 signalled = asyncResults [i].AsyncWaitHandle.WaitOne (timeout, false);
2321
2322                                         if (signalled) {
2323                                                 long t2 = DateTime.Now.Ticks;
2324                                                 timeout = AsyncTimeout - TimeSpan.FromTicks (t2 - t1);
2325                                                 if (timeout.Ticks <= 0)
2326                                                         signalled = false;
2327                                         }
2328                                         else {
2329                                                 localParallelTasks [i].TimeoutHandler (asyncResults [i]);
2330                                         }
2331                                 }
2332 #else
2333                                 WaitHandle [] waitArray = new WaitHandle [asyncResults.Count];
2334                                 int i = 0;
2335                                 for (i = 0; i < asyncResults.Count; i++) {
2336                                         waitArray [i] = asyncResults [i].AsyncWaitHandle;
2337                                 }
2338                                 bool allSignalled = WaitHandle.WaitAll (waitArray, AsyncTimeout, false);
2339                                 if (!allSignalled) {
2340                                         for (i = 0; i < asyncResults.Count; i++) {
2341                                                 if (!asyncResults [i].IsCompleted) {
2342                                                         localParallelTasks [i].TimeoutHandler (asyncResults [i]);
2343                                                 }
2344                                         }
2345                                 }
2346 #endif
2347                         }
2348                         DateTime endWait = DateTime.Now;
2349                         TimeSpan elapsed = endWait - startExecution;
2350                         if (elapsed <= AsyncTimeout) {
2351                                 AsyncTimeout -= elapsed;
2352                         }
2353                         else {
2354                                 AsyncTimeout = TimeSpan.FromTicks(0);
2355                         }
2356                 }
2357
2358                 if (serialTasks != null) {
2359                         List<PageAsyncTask> localSerialTasks = serialTasks;
2360                         serialTasks = null; // Shouldn't execute tasks twice
2361                         foreach (PageAsyncTask serialTask in localSerialTasks) {
2362                                 DateTime startExecution = DateTime.Now;
2363
2364                                 IAsyncResult result = serialTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), serialTask);
2365                                 if (result.CompletedSynchronously) {
2366                                         serialTask.EndHandler (result);
2367                                 }
2368                                 else {
2369                                         bool done = result.AsyncWaitHandle.WaitOne (AsyncTimeout, false);
2370                                         if (!done && !result.IsCompleted) {
2371                                                 serialTask.TimeoutHandler (result);
2372                                         }
2373                                 }
2374                                 DateTime endWait = DateTime.Now;
2375                                 TimeSpan elapsed = endWait - startExecution;
2376                                 if (elapsed <= AsyncTimeout) {
2377                                         AsyncTimeout -= elapsed;
2378                                 }
2379                                 else {
2380                                         AsyncTimeout = TimeSpan.FromTicks (0);
2381                                 }
2382                         }
2383                 }
2384                 AsyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
2385         }
2386
2387         void EndAsyncTaskCallback (IAsyncResult result) 
2388         {
2389                 PageAsyncTask task = (PageAsyncTask)result.AsyncState;
2390                 task.EndHandler (result);
2391         }
2392
2393         public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
2394         {
2395                 Type htmlTextWriterType = typeof (HtmlTextWriter);
2396                 
2397                 if (!htmlTextWriterType.IsAssignableFrom (writerType)) {
2398                         throw new HttpException (String.Format ("Type '{0}' cannot be assigned to HtmlTextWriter", writerType.FullName));
2399                 }
2400
2401                 ConstructorInfo constructor = writerType.GetConstructor (new Type [] { typeof (TextWriter) });
2402                 if (constructor == null) {
2403                         throw new HttpException (String.Format ("Type '{0}' does not have a consturctor that takes a TextWriter as parameter", writerType.FullName));
2404                 }
2405
2406                 return (HtmlTextWriter) Activator.CreateInstance(writerType, tw);
2407         }
2408
2409         public ViewStateEncryptionMode ViewStateEncryptionMode {
2410                 get { return viewStateEncryptionMode; }
2411                 set { viewStateEncryptionMode = value; }
2412         }
2413
2414         public void RegisterRequiresViewStateEncryption ()
2415         {
2416                 controlRegisteredForViewStateEncryption = true;
2417         }
2418
2419         private static byte [] AES_IV = null;
2420         private static byte [] TripleDES_IV = null;
2421         private static object locker = new object ();
2422         private static bool isEncryptionInitialized = false;
2423
2424         private static void InitializeEncryption () 
2425         {
2426                 if (isEncryptionInitialized) {
2427                         return;
2428                 }
2429
2430                 lock (locker) {
2431                         if (isEncryptionInitialized) {
2432                                 return;
2433                         }
2434
2435                         string iv_string = "0BA48A9E-736D-40f8-954B-B2F62241F282";
2436                         AES_IV = new byte [16];
2437                         TripleDES_IV = new byte [8];
2438
2439                         int i;
2440                         for (i = 0; i < AES_IV.Length; i++) {
2441                                 AES_IV [i] = (byte) iv_string [i];
2442                         }
2443
2444                         for (i = 0; i < TripleDES_IV.Length; i++) {
2445                                 TripleDES_IV [i] = (byte) iv_string [i];
2446                         }
2447
2448                         isEncryptionInitialized = true;
2449                 }
2450         }
2451
2452         internal ICryptoTransform GetCryptoTransform (CryptoStreamMode cryptoStreamMode) 
2453         {
2454                 ICryptoTransform transform = null;
2455                 MachineKeySection config = (MachineKeySection) WebConfigurationManager.GetSection (machineKeyConfigPath);
2456                 byte [] vk = MachineKeySectionUtils.ValidationKeyBytes (config);
2457
2458                 switch (config.Validation) {
2459                 case MachineKeyValidation.SHA1:
2460                         transform = SHA1.Create ();
2461                         break;
2462
2463                 case MachineKeyValidation.MD5:
2464                         transform = MD5.Create ();
2465                         break;
2466
2467                 case MachineKeyValidation.AES:
2468                         if (cryptoStreamMode == CryptoStreamMode.Read){
2469                                 transform = Rijndael.Create().CreateDecryptor(vk, AES_IV);
2470                         } else {
2471                                 transform = Rijndael.Create().CreateEncryptor(vk, AES_IV);
2472                         }
2473                         break;
2474
2475                 case MachineKeyValidation.TripleDES:
2476                         if (cryptoStreamMode == CryptoStreamMode.Read){
2477                                 transform = TripleDES.Create().CreateDecryptor(vk, TripleDES_IV);
2478                         } else {
2479                                 transform = TripleDES.Create().CreateEncryptor(vk, TripleDES_IV);
2480                         }
2481                         break;
2482                 }
2483
2484                 return transform;
2485         }
2486
2487         internal bool NeedViewStateEncryption {
2488                 get {
2489                         return (ViewStateEncryptionMode == ViewStateEncryptionMode.Always ||
2490                                         (ViewStateEncryptionMode == ViewStateEncryptionMode.Auto &&
2491                                          controlRegisteredForViewStateEncryption));
2492
2493                 }
2494         }
2495
2496         void ApplyMasterPage ()
2497         {
2498                 if (masterPageFile != null && masterPageFile.Length > 0) {
2499                         ArrayList appliedMasterPageFiles = new ArrayList ();
2500
2501                         if (Master != null) {
2502                                 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
2503
2504                                 Master.Page = this;
2505                                 Controls.Clear ();
2506                                 Controls.Add (Master);
2507                         }
2508                 }
2509         }
2510
2511         [DefaultValueAttribute ("")]
2512         public virtual string MasterPageFile {
2513                 get { return masterPageFile; }
2514                 set {
2515                         masterPageFile = value;
2516                         masterPage = null;
2517                 }
2518         }
2519         
2520         [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2521         [BrowsableAttribute (false)]
2522         public MasterPage Master {
2523                 get {
2524                         if (Context == null || String.IsNullOrEmpty (masterPageFile))
2525                                 return null;
2526
2527                         if (masterPage == null)
2528                                 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
2529
2530                         return masterPage;
2531                 }
2532         }
2533         
2534         public void SetFocus (string clientID)
2535         {
2536                 if (String.IsNullOrEmpty (clientID))
2537                         throw new ArgumentNullException ("control");
2538
2539                 if (_lifeCycle > PageLifeCycle.PreRender)
2540                         throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
2541
2542                 if(Form==null)
2543                         throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
2544
2545                 _focusedControlID = clientID;
2546         }
2547
2548         public void SetFocus (Control control)
2549         {
2550                 if (control == null)
2551                         throw new ArgumentNullException ("control");
2552
2553                 SetFocus (control.ClientID);
2554         }
2555         
2556         [EditorBrowsable (EditorBrowsableState.Advanced)]
2557         public void RegisterRequiresControlState (Control control)
2558         {
2559                 if (control == null)
2560                         throw new ArgumentNullException ("control");
2561
2562                 if (RequiresControlState (control))
2563                         return;
2564
2565                 if (requireStateControls == null)
2566                         requireStateControls = new ArrayList ();
2567                 int n = requireStateControls.Add (control);
2568
2569                 if (_savedControlState == null || n >= _savedControlState.Length) 
2570                         return;
2571
2572                 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2573                         if (parent.IsChildControlStateCleared)
2574                                 return;
2575
2576                 object state = _savedControlState [n];
2577                 if (state != null)
2578                         control.LoadControlState (state);
2579         }
2580         
2581         public bool RequiresControlState (Control control)
2582         {
2583                 if (requireStateControls == null) return false;
2584                 return requireStateControls.Contains (control);
2585         }
2586         
2587         [EditorBrowsable (EditorBrowsableState.Advanced)]
2588         public void UnregisterRequiresControlState (Control control)
2589         {
2590                 if (requireStateControls != null)
2591                         requireStateControls.Remove (control);
2592         }
2593         
2594         public ValidatorCollection GetValidators (string validationGroup)
2595         {                       
2596                 if (validationGroup == String.Empty)
2597                         validationGroup = null;
2598
2599                 ValidatorCollection col = new ValidatorCollection ();
2600                 if (_validators == null)
2601                         return col;
2602                 
2603                 foreach (IValidator v in _validators)
2604                         if (BelongsToGroup(v, validationGroup))
2605                                 col.Add(v);
2606
2607                 return col;
2608         }
2609         
2610         bool BelongsToGroup(IValidator v, string validationGroup) {
2611                 BaseValidator validator = v as BaseValidator;
2612                 if (validationGroup == null)
2613                         return validator == null || String.IsNullOrEmpty (validator.ValidationGroup); 
2614                 else
2615                         return validator != null && validator.ValidationGroup == validationGroup;                       
2616         }
2617         
2618         public virtual void Validate (string validationGroup)
2619         {
2620                 is_validated = true;
2621                 ValidateCollection (GetValidators (validationGroup));
2622         }
2623
2624         object SavePageControlState ()
2625         {
2626                 if (requireStateControls == null) return null;
2627                 object[] state = new object [requireStateControls.Count];
2628                 
2629                 bool allNull = true;
2630                 for (int n=0; n<state.Length; n++) {
2631                         state [n] = ((Control) requireStateControls [n]).SaveControlState ();
2632                         if (state [n] != null) allNull = false;
2633                 }
2634                 if (allNull) return null;
2635                 else return state;
2636         }
2637         
2638         void LoadPageControlState (object data)
2639         {
2640                 _savedControlState = (object []) data;
2641                 
2642                 if (requireStateControls == null) return;
2643
2644                 int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2645                 for (int n=0; n < max; n++) {
2646                         Control ctl = (Control) requireStateControls [n];
2647                         ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2648                 }
2649         }
2650
2651         void LoadPreviousPageReference ()
2652         {
2653                 if (_requestValueCollection != null) {
2654                         string prevPage = _requestValueCollection [PreviousPageID];
2655                         if (prevPage != null) {
2656 #if TARGET_J2EE
2657                                 if (getFacesContext () != null) {
2658                                         IHttpHandler handler = Context.ApplicationInstance.GetHandler (Context, prevPage);
2659                                         Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
2660                                         if (_context.Items.Contains (CrossPagePostBack)) {
2661                                                 previousPage = (Page) _context.Items [CrossPagePostBack];
2662                                                 _context.Items.Remove (CrossPagePostBack);
2663                                         }
2664                                         return;
2665                                 }
2666 #else
2667                                 IHttpHandler handler = PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
2668                                 previousPage = (Page) handler;
2669                                 previousPage.isCrossPagePostBack = true;
2670                                 Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
2671 #endif
2672                         } 
2673                 }
2674         }
2675
2676
2677         Hashtable contentTemplates;
2678         [EditorBrowsable (EditorBrowsableState.Never)]
2679         protected internal void AddContentTemplate (string templateName, ITemplate template)
2680         {
2681                 if (contentTemplates == null)
2682                         contentTemplates = new Hashtable ();
2683                 contentTemplates [templateName] = template;
2684         }
2685
2686         PageTheme _pageTheme;
2687         internal PageTheme PageTheme {
2688                 get { return _pageTheme; }
2689         }
2690
2691         PageTheme _styleSheetPageTheme;
2692         internal PageTheme StyleSheetPageTheme {
2693                 get { return _styleSheetPageTheme; }
2694         }
2695
2696         Stack dataItemCtx;
2697         
2698         internal void PushDataItemContext (object o) {
2699                 if (dataItemCtx == null)
2700                         dataItemCtx = new Stack ();
2701                 
2702                 dataItemCtx.Push (o);
2703         }
2704         
2705         internal void PopDataItemContext () {
2706                 if (dataItemCtx == null)
2707                         throw new InvalidOperationException ();
2708                 
2709                 dataItemCtx.Pop ();
2710         }
2711         
2712         public object GetDataItem() {
2713                 if (dataItemCtx == null || dataItemCtx.Count == 0)
2714                         throw new InvalidOperationException ("No data item");
2715                 
2716                 return dataItemCtx.Peek ();
2717         }
2718
2719         protected internal override void OnInit (EventArgs e)
2720         {
2721                 base.OnInit (e);
2722
2723                 ArrayList themes = new ArrayList();
2724
2725                 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2726                         themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2727                 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2728                         themes.AddRange (PageTheme.GetStyleSheets ());
2729
2730                 if (themes.Count > 0 && Header == null)
2731                         throw new InvalidOperationException ("Using themed css files requires a header control on the page.");
2732
2733                 foreach (string lss in themes) {
2734                         HtmlLink hl = new HtmlLink ();
2735                         hl.Href = lss;
2736                         hl.Attributes["type"] = "text/css";
2737                         hl.Attributes["rel"] = "stylesheet";
2738                         Header.Controls.Add (hl);
2739                 }
2740         }
2741
2742         #endif
2743
2744 #if NET_2_0
2745         [MonoTODO ("Not implemented.  Only used by .net aspx parser")]
2746         protected object GetWrappedFileDependencies (string [] list)
2747         {
2748                 return list;
2749         }
2750
2751         [MonoTODO ("Does nothing.  Used by .net aspx parser")]
2752         protected virtual void InitializeCulture ()
2753         {
2754         }
2755
2756         [MonoTODO ("Does nothing. Used by .net aspx parser")]
2757         protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
2758         {
2759         }
2760 #endif
2761 }
2762 }