2 // System.Web.UI.Page.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Gonzalo Paniagua (gonzalo@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // Marek Habersack (mhabersack@novell.com)
10 // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
11 // Copyright (C) 2003-2010 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Collections.Generic;
36 using System.Collections.Specialized;
37 using System.ComponentModel;
38 using System.ComponentModel.Design;
39 using System.ComponentModel.Design.Serialization;
40 using System.Globalization;
42 using System.Security.Cryptography;
43 using System.Security.Permissions;
44 using System.Security.Principal;
46 using System.Threading;
48 using System.Web.Caching;
49 using System.Web.Compilation;
50 using System.Web.Configuration;
51 using System.Web.SessionState;
52 using System.Web.Util;
53 using System.Web.UI.Adapters;
54 using System.Web.UI.HtmlControls;
55 using System.Web.UI.WebControls;
56 using System.Reflection;
58 namespace System.Web.UI
61 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
62 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
63 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
65 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
67 public partial class Page : TemplateControl, IHttpHandler
69 static string machineKeyConfigPath = "system.web/machineKey";
70 bool _eventValidation = true;
71 object [] _savedControlState;
72 bool _doLoadPreviousPage;
73 string _focusedControlID;
74 bool _hasEnabledControlArray;
79 bool _smartNavigation;
81 ValidatorCollection _validators;
83 string _savedViewState;
84 ArrayList _requiresPostBack;
85 ArrayList _requiresPostBackCopy;
86 ArrayList requiresPostDataChanged;
87 IPostBackEventHandler requiresRaiseEvent;
88 IPostBackEventHandler formPostedRequiresRaiseEvent;
89 NameValueCollection secondPostData;
90 bool requiresPostBackScript;
91 bool postBackScriptRendered;
92 bool requiresFormScriptDeclaration;
93 bool formScriptDeclarationRendered;
95 string viewStateUserKey;
96 NameValueCollection _requestValueCollection;
98 ClientScriptManager scriptManager;
99 bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
100 PageStatePersister page_state_persister;
101 CultureInfo _appCulture;
102 CultureInfo _appUICulture;
104 // The initial context
105 HttpContext _context;
107 // cached from the initial context
108 HttpApplicationState _application;
109 HttpResponse _response;
110 HttpRequest _request;
113 HttpSessionState _session;
115 [EditorBrowsable (EditorBrowsableState.Never)]
116 public const string postEventArgumentID = "__EVENTARGUMENT";
118 [EditorBrowsable (EditorBrowsableState.Never)]
119 public const string postEventSourceID = "__EVENTTARGET";
121 const string ScrollPositionXID = "__SCROLLPOSITIONX";
122 const string ScrollPositionYID = "__SCROLLPOSITIONY";
123 const string EnabledControlArrayID = "__enabledControlArray";
124 internal const string LastFocusID = "__LASTFOCUS";
125 internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
126 internal const string CallbackSourceID = "__CALLBACKTARGET";
127 internal const string PreviousPageID = "__PREVIOUSPAGE";
129 int maxPageStateFieldLength = -1;
130 string uniqueFilePathSuffix;
133 MasterPage masterPage;
134 string masterPageFile;
137 bool isCrossPagePostBack;
140 List <Control> requireStateControls;
145 string _styleSheetTheme;
148 bool _maintainScrollPositionOnPostBack;
150 bool asyncMode = false;
151 TimeSpan asyncTimeout;
152 const double DefaultAsyncTimeout = 45.0;
153 List<PageAsyncTask> parallelTasks;
154 List<PageAsyncTask> serialTasks;
156 ViewStateEncryptionMode viewStateEncryptionMode;
157 bool controlRegisteredForViewStateEncryption = false;
162 scriptManager = new ClientScriptManager (this);
165 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
167 asyncTimeout = ps.AsyncTimeout;
168 viewStateEncryptionMode = ps.ViewStateEncryptionMode;
169 _viewState = ps.EnableViewState;
171 asyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
172 viewStateEncryptionMode = ViewStateEncryptionMode.Auto;
181 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
183 public HttpApplicationState Application {
184 get { return _application; }
187 [EditorBrowsable (EditorBrowsableState.Never)]
188 protected bool AspCompatMode {
189 get { return false; }
190 set { throw new NotImplementedException (); }
193 [EditorBrowsable (EditorBrowsableState.Never)]
194 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
195 [BrowsableAttribute (false)]
197 get { return Response.BufferOutput; }
198 set { Response.BufferOutput = value; }
201 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
206 throw new HttpException ("Cache is not available.");
211 [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
212 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
213 [Browsable (false), DefaultValue ("")]
214 [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
215 public string ClientTarget {
216 get { return (clientTarget == null) ? "" : clientTarget; }
218 clientTarget = value;
224 [EditorBrowsable (EditorBrowsableState.Never)]
225 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
226 [BrowsableAttribute (false)]
227 public int CodePage {
228 get { return Response.ContentEncoding.CodePage; }
229 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
232 [EditorBrowsable (EditorBrowsableState.Never)]
233 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
234 [BrowsableAttribute (false)]
235 public string ContentType {
236 get { return Response.ContentType; }
237 set { Response.ContentType = value; }
240 protected internal override HttpContext Context {
242 if (_context == null)
243 return HttpContext.Current;
249 [EditorBrowsable (EditorBrowsableState.Advanced)]
250 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
251 [BrowsableAttribute (false)]
252 public string Culture {
253 get { return Thread.CurrentThread.CurrentCulture.Name; }
254 set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
257 public virtual bool EnableEventValidation {
258 get { return _eventValidation; }
261 throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
262 _eventValidation = value;
267 public override bool EnableViewState {
268 get { return _viewState; }
269 set { _viewState = value; }
272 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
273 [BrowsableAttribute (false)]
274 [EditorBrowsable (EditorBrowsableState.Never)]
275 public bool EnableViewStateMac {
276 get { return _viewStateMac; }
277 set { _viewStateMac = value; }
280 internal bool EnableViewStateMacInternal {
281 get { return _viewStateMac; }
282 set { _viewStateMac = value; }
285 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
286 [Browsable (false), DefaultValue ("")]
287 [WebSysDescription ("The URL of a page used for error redirection.")]
288 public string ErrorPage {
289 get { return _errorPage; }
291 HttpContext ctx = Context;
295 ctx.ErrorPage = value;
300 [EditorBrowsable (EditorBrowsableState.Never)]
301 protected ArrayList FileDependencies {
303 if (Response != null)
304 Response.AddFileDependencies (value);
309 [EditorBrowsable (EditorBrowsableState.Never)]
310 public override string ID {
311 get { return base.ID; }
312 set { base.ID = value; }
315 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
317 public bool IsPostBack {
318 get { return isPostBack; }
321 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
322 public bool IsReusable {
323 get { return false; }
326 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
328 public bool IsValid {
331 throw new HttpException (Locale.GetText ("Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate."));
333 foreach (IValidator val in Validators)
340 public IDictionary Items {
343 items = new Hashtable ();
348 [EditorBrowsable (EditorBrowsableState.Never)]
349 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
350 [BrowsableAttribute (false)]
352 get { return Thread.CurrentThread.CurrentCulture.LCID; }
353 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
357 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
358 public bool MaintainScrollPositionOnPostBack {
359 get { return _maintainScrollPositionOnPostBack; }
360 set { _maintainScrollPositionOnPostBack = value; }
363 public PageAdapter PageAdapter {
365 return Adapter as PageAdapter;
369 string _validationStartupScript;
370 string _validationOnSubmitStatement;
371 string _validationInitializeScript;
372 string _webFormScriptReference;
374 internal string WebFormScriptReference {
376 if (_webFormScriptReference == null)
377 _webFormScriptReference = IsMultiForm ? theForm : "window";
378 return _webFormScriptReference;
382 internal string ValidationStartupScript {
384 if (_validationStartupScript == null) {
385 _validationStartupScript =
387 " + WebFormScriptReference + @".Page_ValidationActive = false;
388 " + WebFormScriptReference + @".ValidatorOnLoad();
389 " + WebFormScriptReference + @".ValidatorOnSubmit = function () {
390 if (this.Page_ValidationActive) {
391 return this.ValidatorCommonOnSubmit();
397 return _validationStartupScript;
401 internal string ValidationOnSubmitStatement {
403 if (_validationOnSubmitStatement == null)
404 _validationOnSubmitStatement = "if (!" + WebFormScriptReference + ".ValidatorOnSubmit()) return false;";
405 return _validationOnSubmitStatement;
409 internal string ValidationInitializeScript {
411 if (_validationInitializeScript == null)
412 _validationInitializeScript = "WebFormValidation_Initialize(" + WebFormScriptReference + ");";
413 return _validationInitializeScript;
417 internal IScriptManager ScriptManager {
418 get { return (IScriptManager) Items [typeof (IScriptManager)]; }
421 internal string theForm {
427 internal bool IsMultiForm {
428 get { return false; }
432 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
434 public HttpRequest Request {
436 if (_request == null)
437 throw new HttpException("Request is not available in this context.");
442 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
444 public HttpResponse Response {
446 if (_response == null)
447 throw new HttpException ("Response is not available in this context.");
452 [EditorBrowsable (EditorBrowsableState.Never)]
453 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
454 [BrowsableAttribute (false)]
455 public string ResponseEncoding {
456 get { return Response.ContentEncoding.WebName; }
457 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
460 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
462 public HttpServerUtility Server {
463 get { return Context.Server; }
466 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
468 public virtual HttpSessionState Session {
470 if (_session != null)
474 _session = Context.Session;
476 // ignore, should not throw
479 if (_session == null)
480 throw new HttpException ("Session state can only be used " +
481 "when enableSessionState is set to true, either " +
482 "in a configuration file or in the Page directive.");
488 [FilterableAttribute (false)]
491 public bool SmartNavigation {
492 get { return _smartNavigation; }
493 set { _smartNavigation = value; }
496 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
499 public virtual string StyleSheetTheme {
500 get { return _styleSheetTheme; }
501 set { _styleSheetTheme = value; }
505 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
506 public virtual string Theme {
507 get { return _theme; }
508 set { _theme = value; }
511 void InitializeStyleSheet ()
513 if (_styleSheetTheme == null) {
514 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
516 _styleSheetTheme = ps.StyleSheetTheme;
519 if (_styleSheetTheme != null && _styleSheetTheme != "")
520 _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, Context);
522 if (!String.IsNullOrEmpty (_styleSheetTheme)) {
523 string virtualPath = "~/App_Themes/" + _styleSheetTheme;
524 _styleSheetPageTheme = BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (PageTheme)) as PageTheme;
529 void InitializeTheme ()
531 if (_theme == null) {
532 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
537 if (_theme != null && _theme != "") {
538 _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, Context);
539 _pageTheme.SetPage (this);
542 if (!String.IsNullOrEmpty (_theme)) {
543 string virtualPath = "~/App_Themes/" + _theme;
544 _pageTheme = BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (PageTheme)) as PageTheme;
545 if (_pageTheme != null)
546 _pageTheme.SetPage (this);
553 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
554 public string Title {
556 if (_title == null) {
557 if (htmlHeader != null && htmlHeader.Title != null)
558 return htmlHeader.Title;
565 if (htmlHeader != null)
566 htmlHeader.Title = value;
572 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
574 public TraceContext Trace {
575 get { return Context.Trace; }
578 [EditorBrowsable (EditorBrowsableState.Never)]
579 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
580 [BrowsableAttribute (false)]
581 public bool TraceEnabled {
582 get { return Trace.IsEnabled; }
583 set { Trace.IsEnabled = value; }
586 [EditorBrowsable (EditorBrowsableState.Never)]
587 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
588 [BrowsableAttribute (false)]
589 public TraceMode TraceModeValue {
590 get { return Trace.TraceMode; }
591 set { Trace.TraceMode = value; }
594 [EditorBrowsable (EditorBrowsableState.Never)]
595 protected int TransactionMode {
596 get { return _transactionMode; }
597 set { _transactionMode = value; }
600 [EditorBrowsable (EditorBrowsableState.Advanced)]
601 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
602 [BrowsableAttribute (false)]
603 public string UICulture {
604 get { return Thread.CurrentThread.CurrentUICulture.Name; }
605 set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
608 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
610 public IPrincipal User {
611 get { return Context.User; }
614 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
616 public ValidatorCollection Validators {
618 if (_validators == null)
619 _validators = new ValidatorCollection ();
624 [MonoTODO ("Use this when encrypting/decrypting ViewState")]
626 public string ViewStateUserKey {
627 get { return viewStateUserKey; }
628 set { viewStateUserKey = value; }
632 public override bool Visible {
633 get { return base.Visible; }
634 set { base.Visible = value; }
641 CultureInfo GetPageCulture (string culture, CultureInfo deflt)
645 CultureInfo ret = null;
646 if (culture.StartsWith ("auto", StringComparison.InvariantCultureIgnoreCase)) {
648 if (!Context.IsServletRequest)
651 string[] languages = Request.UserLanguages;
653 if (languages != null && languages.Length > 0)
654 ret = CultureInfo.CreateSpecificCulture (languages[0]);
661 ret = CultureInfo.CreateSpecificCulture (culture);
666 [EditorBrowsable (EditorBrowsableState.Never)]
667 protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
671 throw new NotImplementedException ();
674 [EditorBrowsable (EditorBrowsableState.Never)]
675 protected void AspCompatEndProcessRequest (IAsyncResult result)
677 throw new NotImplementedException ();
680 [EditorBrowsable (EditorBrowsableState.Advanced)]
681 protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
683 if (Request.BrowserMightHaveSpecialWriter)
684 return Request.Browser.CreateHtmlTextWriter(tw);
686 return new HtmlTextWriter (tw);
689 [EditorBrowsable (EditorBrowsableState.Never)]
690 public void DesignerInitialize ()
692 InitRecursive (null);
695 [EditorBrowsable (EditorBrowsableState.Advanced)]
696 protected internal virtual NameValueCollection DeterminePostBackMode ()
698 // if request was transfered from other page such Transfer
699 if (_context.IsProcessingInclude)
702 HttpRequest req = Request;
706 NameValueCollection coll = null;
707 if (0 == String.Compare (Request.HttpMethod, "POST", true, Helpers.InvariantCulture)
709 || !_context.IsServletRequest
714 string query = Request.QueryStringRaw;
715 if (query == null || query.Length == 0)
718 coll = req.QueryString;
721 WebROCollection c = (WebROCollection) coll;
722 allow_load = !c.GotID;
724 c.ID = GetTypeHashCode ();
726 allow_load = (c.ID == GetTypeHashCode ());
728 if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
731 if (getFacesContext () != null && _context.Handler != _context.CurrentHandler) {
732 // check if it is PreviousPage
733 string prevViewId = coll [PreviousPageID];
734 if (!String.IsNullOrEmpty (prevViewId)) {
735 string appPath = VirtualPathUtility.RemoveTrailingSlash (Request.ApplicationPath);
736 prevViewId = prevViewId.Substring (appPath.Length);
737 isCrossPagePostBack = String.Compare (prevViewId, getFacesContext ().getExternalContext ().getRequestPathInfo (), StringComparison.OrdinalIgnoreCase) == 0;
744 public override Control FindControl (string id) {
748 return base.FindControl (id);
751 Control FindControl (string id, bool decode) {
754 id = DecodeNamespace (id);
756 return FindControl (id);
760 [EditorBrowsable (EditorBrowsableState.Advanced)]
761 public string GetPostBackClientEvent (Control control, string argument)
763 return scriptManager.GetPostBackEventReference (control, argument);
767 [EditorBrowsable (EditorBrowsableState.Advanced)]
768 public string GetPostBackClientHyperlink (Control control, string argument)
770 return scriptManager.GetPostBackClientHyperlink (control, argument);
774 [EditorBrowsable (EditorBrowsableState.Advanced)]
775 public string GetPostBackEventReference (Control control)
777 return scriptManager.GetPostBackEventReference (control, "");
781 [EditorBrowsable (EditorBrowsableState.Advanced)]
782 public string GetPostBackEventReference (Control control, string argument)
784 return scriptManager.GetPostBackEventReference (control, argument);
787 internal void RequiresFormScriptDeclaration ()
789 requiresFormScriptDeclaration = true;
792 internal void RequiresPostBackScript ()
794 if (requiresPostBackScript)
796 ClientScript.RegisterHiddenField (postEventSourceID, String.Empty);
797 ClientScript.RegisterHiddenField (postEventArgumentID, String.Empty);
798 requiresPostBackScript = true;
799 RequiresFormScriptDeclaration ();
802 [EditorBrowsable (EditorBrowsableState.Never)]
803 public virtual int GetTypeHashCode ()
808 [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, SqlDependency")]
809 protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
811 if (cacheSettings.Enabled) {
812 InitOutputCache(cacheSettings.Duration,
813 cacheSettings.VaryByContentEncoding,
814 cacheSettings.VaryByHeader,
815 cacheSettings.VaryByCustom,
816 cacheSettings.Location,
817 cacheSettings.VaryByParam);
819 HttpResponse response = Response;
820 HttpCachePolicy cache = response != null ? response.Cache : null;
821 if (cache != null && cacheSettings.NoStore)
825 [MonoTODO ("varyByContentEncoding is not currently used")]
826 protected virtual void InitOutputCache(int duration,
827 string varyByContentEncoding,
830 OutputCacheLocation location,
833 HttpResponse response = Response;
834 HttpCachePolicy cache = response.Cache;
835 bool set_vary = false;
836 HttpContext ctx = Context;
837 DateTime timestamp = ctx != null ? ctx.Timestamp : DateTime.Now;
840 case OutputCacheLocation.Any:
841 cache.SetCacheability (HttpCacheability.Public);
842 cache.SetMaxAge (new TimeSpan (0, 0, duration));
843 cache.SetLastModified (timestamp);
846 case OutputCacheLocation.Client:
847 cache.SetCacheability (HttpCacheability.Private);
848 cache.SetMaxAge (new TimeSpan (0, 0, duration));
849 cache.SetLastModified (timestamp);
851 case OutputCacheLocation.Downstream:
852 cache.SetCacheability (HttpCacheability.Public);
853 cache.SetMaxAge (new TimeSpan (0, 0, duration));
854 cache.SetLastModified (timestamp);
856 case OutputCacheLocation.Server:
857 cache.SetCacheability (HttpCacheability.Server);
860 case OutputCacheLocation.None:
865 if (varyByCustom != null)
866 cache.SetVaryByCustom (varyByCustom);
868 if (varyByParam != null && varyByParam.Length > 0) {
869 string[] prms = varyByParam.Split (';');
870 foreach (string p in prms)
871 cache.VaryByParams [p.Trim ()] = true;
872 cache.VaryByParams.IgnoreParams = false;
874 cache.VaryByParams.IgnoreParams = true;
877 if (varyByHeader != null && varyByHeader.Length > 0) {
878 string[] hdrs = varyByHeader.Split (';');
879 foreach (string h in hdrs)
880 cache.VaryByHeaders [h.Trim ()] = true;
883 if (PageAdapter != null) {
884 if (PageAdapter.CacheVaryByParams != null) {
885 foreach (string p in PageAdapter.CacheVaryByParams)
886 cache.VaryByParams [p] = true;
888 if (PageAdapter.CacheVaryByHeaders != null) {
889 foreach (string h in PageAdapter.CacheVaryByHeaders)
890 cache.VaryByHeaders [h] = true;
895 response.IsCached = true;
896 cache.Duration = duration;
897 cache.SetExpires (timestamp.AddSeconds (duration));
901 [EditorBrowsable (EditorBrowsableState.Never)]
902 protected virtual void InitOutputCache (int duration,
905 OutputCacheLocation location,
908 InitOutputCache (duration, null, varyByHeader, varyByCustom, location, varyByParam);
912 public bool IsClientScriptBlockRegistered (string key)
914 return scriptManager.IsClientScriptBlockRegistered (key);
918 public bool IsStartupScriptRegistered (string key)
920 return scriptManager.IsStartupScriptRegistered (key);
923 public string MapPath (string virtualPath)
925 return Request.MapPath (virtualPath);
928 protected internal override void Render (HtmlTextWriter writer)
930 if (MaintainScrollPositionOnPostBack) {
931 ClientScript.RegisterWebFormClientScript ();
933 ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
934 ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
936 StringBuilder script = new StringBuilder ();
937 script.AppendLine ("<script type=\"text/javascript\">");
938 script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_START);
939 script.AppendLine (theForm + ".oldSubmit = " + theForm + ".submit;");
940 script.AppendLine (theForm + ".submit = function () { " + WebFormScriptReference + ".WebForm_SaveScrollPositionSubmit(); }");
941 script.AppendLine (theForm + ".oldOnSubmit = " + theForm + ".onsubmit;");
942 script.AppendLine (theForm + ".onsubmit = function () { " + WebFormScriptReference + ".WebForm_SaveScrollPositionOnSubmit(); }");
944 script.AppendLine (theForm + ".oldOnLoad = window.onload;");
945 script.AppendLine ("window.onload = function () { " + WebFormScriptReference + ".WebForm_RestoreScrollPosition (); };");
947 script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_END);
948 script.AppendLine ("</script>");
950 ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
953 if (bool.Parse (WebConfigurationManager.AppSettings [RenderBodyContentOnlyKey] ?? "false")) {
954 for (Control c = this.Form; c != null; c = c.Parent) {
955 HtmlGenericControl ch = (c as HtmlGenericControl);
956 if (ch != null && ch.TagName == "body") {
957 ch.RenderChildren (writer);
963 base.Render (writer);
966 void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
969 ClientScriptManager.WriteBeginScriptBlock (writer);
970 RenderClientScriptFormDeclaration (writer, formUniqueID);
971 writer.WriteLine (WebFormScriptReference + "._form = " + theForm + ";");
972 writer.WriteLine (WebFormScriptReference + ".__doPostBack = function (eventTarget, eventArgument) {");
973 writer.WriteLine ("\tif(" + theForm + ".onsubmit && " + theForm + ".onsubmit() == false) return;");
974 writer.WriteLine ("\t" + theForm + "." + postEventSourceID + ".value = eventTarget;");
975 writer.WriteLine ("\t" + theForm + "." + postEventArgumentID + ".value = eventArgument;");
976 writer.WriteLine ("\t" + theForm + ".submit();");
977 writer.WriteLine ("}");
978 ClientScriptManager.WriteEndScriptBlock (writer);
981 void RenderClientScriptFormDeclaration (HtmlTextWriter writer, string formUniqueID)
983 if (formScriptDeclarationRendered)
986 if (PageAdapter != null) {
987 writer.WriteLine ("\tvar {0} = {1};\n", theForm, PageAdapter.GetPostBackFormReference(formUniqueID));
989 writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
990 writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
993 // TODO implement callback on portlet
994 string serverUrl = Request.RawUrl;
995 writer.WriteLine ("\t{0}.serverURL = {1};", theForm, ClientScriptManager.GetScriptLiteral (serverUrl));
996 writer.WriteLine ("\twindow.TARGET_J2EE = true;");
997 writer.WriteLine ("\twindow.IsMultiForm = {0};", IsMultiForm ? "true" : "false");
999 formScriptDeclarationRendered = true;
1002 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
1005 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
1007 renderingForm = true;
1008 writer.WriteLine ();
1010 if (requiresFormScriptDeclaration || (scriptManager != null && scriptManager.ScriptsPresent) || PageAdapter != null) {
1011 ClientScriptManager.WriteBeginScriptBlock (writer);
1012 RenderClientScriptFormDeclaration (writer, formUniqueID);
1013 ClientScriptManager.WriteEndScriptBlock (writer);
1016 if (handleViewState)
1018 if (getFacesContext () != null) {
1019 javax.faces.application.ViewHandler viewHandler = getFacesContext ().getApplication ().getViewHandler ();
1020 javax.faces.context.ResponseWriter oldFacesWriter = SetupResponseWriter (writer);
1022 viewHandler.writeState (getFacesContext ());
1025 getFacesContext ().setResponseWriter (oldFacesWriter);
1029 scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
1031 scriptManager.WriteHiddenFields (writer);
1032 if (requiresPostBackScript) {
1033 RenderPostBackScript (writer, formUniqueID);
1034 postBackScriptRendered = true;
1037 scriptManager.WriteWebFormClientScript (writer);
1038 scriptManager.WriteClientScriptBlocks (writer);
1041 internal IStateFormatter GetFormatter ()
1043 return new ObjectStateFormatter (this);
1046 internal string GetSavedViewState ()
1048 return _savedViewState;
1051 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1053 scriptManager.SaveEventValidationState ();
1054 scriptManager.WriteExpandoAttributes (writer);
1055 scriptManager.WriteHiddenFields (writer);
1056 if (!postBackScriptRendered && requiresPostBackScript)
1057 RenderPostBackScript (writer, formUniqueID);
1058 scriptManager.WriteWebFormClientScript (writer);
1059 scriptManager.WriteArrayDeclares (writer);
1060 scriptManager.WriteStartupScriptBlocks (writer);
1061 renderingForm = false;
1062 postBackScriptRendered = false;
1065 void ProcessPostData (NameValueCollection data, bool second)
1067 NameValueCollection requestValues = _requestValueCollection == null ?
1068 new NameValueCollection () :
1069 _requestValueCollection;
1071 if (data != null && data.Count > 0) {
1072 Hashtable used = new Hashtable ();
1073 foreach (string id in data.AllKeys) {
1074 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID || id == ClientScriptManager.EventStateFieldName)
1077 if (used.ContainsKey (id))
1082 Control ctrl = FindControl (id, true);
1084 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1085 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1089 formPostedRequiresRaiseEvent = pbeh;
1093 if (pbdh.LoadPostData (id, requestValues) == true) {
1094 if (requiresPostDataChanged == null)
1095 requiresPostDataChanged = new ArrayList ();
1096 requiresPostDataChanged.Add (pbdh);
1099 if (_requiresPostBackCopy != null)
1100 _requiresPostBackCopy.Remove (id);
1102 } else if (!second) {
1103 if (secondPostData == null)
1104 secondPostData = new NameValueCollection ();
1105 secondPostData.Add (id, data [id]);
1110 ArrayList list1 = null;
1111 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1112 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1113 foreach (string id in handlers) {
1114 IPostBackDataHandler pbdh = FindControl (id, true) as IPostBackDataHandler;
1116 _requiresPostBackCopy.Remove (id);
1117 if (pbdh.LoadPostData (id, requestValues)) {
1118 if (requiresPostDataChanged == null)
1119 requiresPostDataChanged = new ArrayList ();
1121 requiresPostDataChanged.Add (pbdh);
1123 } else if (!second) {
1125 list1 = new ArrayList ();
1130 _requiresPostBackCopy = second ? null : list1;
1132 secondPostData = null;
1135 [EditorBrowsable (EditorBrowsableState.Never)]
1136 public virtual void ProcessRequest (HttpContext context)
1138 SetContext (context);
1140 bool wasException = false;
1141 IHttpHandler jsfHandler = getFacesContext () != null ? EnterThread () : null;
1144 if (clientTarget != null)
1145 Request.ClientTarget = clientTarget;
1147 WireupAutomaticEvents ();
1148 //-- Control execution lifecycle in the docs
1150 // Save culture information because it can be modified in FrameworkInitialize()
1151 _appCulture = Thread.CurrentThread.CurrentCulture;
1152 _appUICulture = Thread.CurrentThread.CurrentUICulture;
1153 FrameworkInitialize ();
1154 context.ErrorPage = _errorPage;
1157 InternalProcessRequest ();
1159 } catch (Exception ex) {
1160 wasException = true;
1161 HandleException (ex);
1163 } catch (ThreadAbortException taex) {
1164 if (FlagEnd.Value == taex.ExceptionState)
1165 Thread.ResetAbort ();
1168 } catch (Exception e) {
1169 ProcessException (e);
1173 if (getFacesContext () != null)
1174 ExitThread (jsfHandler);
1175 else if (!wasException)
1181 void ProcessException (Exception e) {
1182 // We want to remove that error, as we're rethrowing to stop
1183 // further processing.
1184 Trace.Warn ("Unhandled Exception", e.ToString (), e);
1185 _context.AddError (e); // OnError might access LastError
1186 OnError (EventArgs.Empty);
1187 if (_context.HasError (e)) {
1188 _context.ClearError (e);
1190 vmw.common.TypeUtils.Throw (e);
1192 throw new HttpUnhandledException (null, e);
1197 void ProcessUnload () {
1200 UnloadRecursive (true);
1203 if (getFacesContext () != null) {
1204 if(IsCrossPagePostBack)
1205 _context.Items [CrossPagePostBack] = this;
1208 if (Thread.CurrentThread.CurrentCulture.Equals (_appCulture) == false)
1209 Thread.CurrentThread.CurrentCulture = _appCulture;
1211 if (Thread.CurrentThread.CurrentUICulture.Equals (_appUICulture) == false)
1212 Thread.CurrentThread.CurrentUICulture = _appUICulture;
1215 _appUICulture = null;
1218 delegate void ProcessRequestDelegate (HttpContext context);
1220 sealed class DummyAsyncResult : IAsyncResult
1222 readonly object state;
1223 readonly WaitHandle asyncWaitHandle;
1224 readonly bool completedSynchronously;
1225 readonly bool isCompleted;
1227 public DummyAsyncResult (bool isCompleted, bool completedSynchronously, object state)
1229 this.isCompleted = isCompleted;
1230 this.completedSynchronously = completedSynchronously;
1233 asyncWaitHandle = new ManualResetEvent (true);
1236 asyncWaitHandle = new ManualResetEvent (false);
1240 #region IAsyncResult Members
1242 public object AsyncState {
1243 get { return state; }
1246 public WaitHandle AsyncWaitHandle {
1247 get { return asyncWaitHandle; }
1250 public bool CompletedSynchronously {
1251 get { return completedSynchronously; }
1254 public bool IsCompleted {
1255 get { return isCompleted; }
1261 protected IAsyncResult AsyncPageBeginProcessRequest (HttpContext context, AsyncCallback callback, object extraData)
1263 ProcessRequest (context);
1264 DummyAsyncResult asyncResult = new DummyAsyncResult (true, true, extraData);
1266 if (callback != null) {
1267 callback (asyncResult);
1273 protected void AsyncPageEndProcessRequest (IAsyncResult result)
1277 void InternalProcessRequest ()
1279 if (PageAdapter != null)
1280 _requestValueCollection = PageAdapter.DeterminePostBackMode();
1282 _requestValueCollection = this.DeterminePostBackMode();
1284 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1285 if (_requestValueCollection != null) {
1286 if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1287 _doLoadPreviousPage = true;
1289 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1290 // LAMESPEC: on Callback IsPostBack is set to false, but true.
1291 //isPostBack = !isCallback;
1295 string lastFocus = _requestValueCollection [LastFocusID];
1296 if (!String.IsNullOrEmpty (lastFocus))
1297 _focusedControlID = UniqueID2ClientID (lastFocus);
1300 if (!isCrossPagePostBack) {
1301 if (_context.PreviousHandler is Page)
1302 previousPage = (Page) _context.PreviousHandler;
1305 Trace.Write ("aspx.page", "Begin PreInit");
1306 OnPreInit (EventArgs.Empty);
1307 Trace.Write ("aspx.page", "End PreInit");
1311 Trace.Write ("aspx.page", "Begin Init");
1312 InitRecursive (null);
1313 Trace.Write ("aspx.page", "End Init");
1315 Trace.Write ("aspx.page", "Begin InitComplete");
1316 OnInitComplete (EventArgs.Empty);
1317 Trace.Write ("aspx.page", "End InitComplete");
1319 renderingForm = false;
1322 if (getFacesContext () != null)
1323 if (IsPostBack || IsCallback)
1327 RestorePageState ();
1329 ProcessRaiseEvents ();
1330 if (ProcessLoadComplete ())
1333 if (getFacesContext () != null) {
1334 getFacesContext ().renderResponse ();
1341 void RestorePageState ()
1343 if (IsPostBack || IsCallback) {
1344 if (_requestValueCollection != null)
1345 scriptManager.RestoreEventValidationState (
1346 _requestValueCollection [ClientScriptManager.EventStateFieldName]);
1347 Trace.Write ("aspx.page", "Begin LoadViewState");
1348 LoadPageViewState ();
1349 Trace.Write ("aspx.page", "End LoadViewState");
1353 void ProcessPostData ()
1355 if (IsPostBack || IsCallback) {
1356 Trace.Write ("aspx.page", "Begin ProcessPostData");
1357 ProcessPostData (_requestValueCollection, false);
1358 Trace.Write ("aspx.page", "End ProcessPostData");
1362 if (IsPostBack || IsCallback) {
1363 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1364 ProcessPostData (secondPostData, true);
1365 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1371 Trace.Write ("aspx.page", "Begin PreLoad");
1372 OnPreLoad (EventArgs.Empty);
1373 Trace.Write ("aspx.page", "End PreLoad");
1375 Trace.Write ("aspx.page", "Begin Load");
1377 Trace.Write ("aspx.page", "End Load");
1380 void ProcessRaiseEvents ()
1382 if (IsPostBack || IsCallback) {
1383 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1384 RaiseChangedEvents ();
1385 Trace.Write ("aspx.page", "End Raise ChangedEvents");
1386 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1387 RaisePostBackEvents ();
1388 Trace.Write ("aspx.page", "End Raise PostBackEvent");
1392 bool ProcessLoadComplete ()
1394 Trace.Write ("aspx.page", "Begin LoadComplete");
1395 OnLoadComplete (EventArgs.Empty);
1396 Trace.Write ("aspx.page", "End LoadComplete");
1398 if (IsCrossPagePostBack)
1403 if (getFacesContext () != null) {
1404 _callbackTarget = GetCallbackTarget ();
1405 ProcessRaiseCallbackEvent (_callbackTarget, ref _callbackEventError);
1409 string result = ProcessCallbackData ();
1410 HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);
1411 callbackOutput.Write (result);
1412 callbackOutput.Flush ();
1416 Trace.Write ("aspx.page", "Begin PreRender");
1417 PreRenderRecursiveInternal ();
1418 Trace.Write ("aspx.page", "End PreRender");
1420 ExecuteRegisteredAsyncTasks ();
1422 Trace.Write ("aspx.page", "Begin PreRenderComplete");
1423 OnPreRenderComplete (EventArgs.Empty);
1424 Trace.Write ("aspx.page", "End PreRenderComplete");
1426 Trace.Write ("aspx.page", "Begin SaveViewState");
1427 SavePageViewState ();
1428 Trace.Write ("aspx.page", "End SaveViewState");
1430 Trace.Write ("aspx.page", "Begin SaveStateComplete");
1431 OnSaveStateComplete (EventArgs.Empty);
1432 Trace.Write ("aspx.page", "End SaveStateComplete");
1436 internal void RenderPage ()
1438 scriptManager.ResetEventValidationState ();
1441 Trace.Write ("aspx.page", "Begin Render");
1442 HtmlTextWriter output = CreateHtmlTextWriter (Response.Output);
1443 RenderControl (output);
1444 Trace.Write ("aspx.page", "End Render");
1447 internal void SetContext (HttpContext context)
1451 _application = context.Application;
1452 _response = context.Response;
1453 _request = context.Request;
1454 _cache = context.Cache;
1459 TraceManager traceManager = HttpRuntime.TraceManager;
1461 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1466 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
1469 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1470 HtmlTextWriter output = new HtmlTextWriter (Response.Output);
1471 Trace.Render (output);
1475 void RaisePostBackEvents ()
1477 Control targetControl;
1478 if (requiresRaiseEvent != null) {
1479 RaisePostBackEvent (requiresRaiseEvent, null);
1483 if (formPostedRequiresRaiseEvent != null) {
1484 RaisePostBackEvent (formPostedRequiresRaiseEvent, null);
1488 NameValueCollection postdata = _requestValueCollection;
1489 if (postdata == null)
1492 string eventTarget = postdata [postEventSourceID];
1493 if (eventTarget == null || eventTarget.Length == 0) {
1494 if (formPostedRequiresRaiseEvent != null)
1495 RaisePostBackEvent (formPostedRequiresRaiseEvent, null);
1501 targetControl = FindControl (eventTarget, true);
1502 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1507 string eventArgument = postdata [postEventArgumentID];
1508 RaisePostBackEvent (target, eventArgument);
1511 internal void RaiseChangedEvents ()
1513 if (requiresPostDataChanged == null)
1516 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1517 ipdh.RaisePostDataChangedEvent ();
1519 requiresPostDataChanged = null;
1522 [EditorBrowsable (EditorBrowsableState.Advanced)]
1523 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1525 sourceControl.RaisePostBackEvent (eventArgument);
1529 [EditorBrowsable (EditorBrowsableState.Advanced)]
1530 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1532 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1536 [EditorBrowsable (EditorBrowsableState.Advanced)]
1537 public virtual void RegisterClientScriptBlock (string key, string script)
1539 scriptManager.RegisterClientScriptBlock (key, script);
1543 [EditorBrowsable (EditorBrowsableState.Advanced)]
1544 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1546 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1549 [MonoTODO("Not implemented, Used in HtmlForm")]
1550 internal void RegisterClientScriptFile (string a, string b, string c)
1552 throw new NotImplementedException ();
1556 [EditorBrowsable (EditorBrowsableState.Advanced)]
1557 public void RegisterOnSubmitStatement (string key, string script)
1559 scriptManager.RegisterOnSubmitStatement (key, script);
1562 internal string GetSubmitStatements ()
1564 return scriptManager.WriteSubmitStatements ();
1567 [EditorBrowsable (EditorBrowsableState.Advanced)]
1568 public void RegisterRequiresPostBack (Control control)
1570 if (!(control is IPostBackDataHandler))
1571 throw new HttpException ("The control to register does not implement the IPostBackDataHandler interface.");
1573 if (_requiresPostBack == null)
1574 _requiresPostBack = new ArrayList ();
1576 if (_requiresPostBack.Contains (control.UniqueID))
1579 _requiresPostBack.Add (control.UniqueID);
1582 [EditorBrowsable (EditorBrowsableState.Advanced)]
1583 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1585 requiresRaiseEvent = control;
1589 [EditorBrowsable (EditorBrowsableState.Advanced)]
1590 public virtual void RegisterStartupScript (string key, string script)
1592 scriptManager.RegisterStartupScript (key, script);
1595 [EditorBrowsable (EditorBrowsableState.Advanced)]
1596 public void RegisterViewStateHandler ()
1598 handleViewState = true;
1601 [EditorBrowsable (EditorBrowsableState.Advanced)]
1602 protected virtual void SavePageStateToPersistenceMedium (object viewState)
1604 PageStatePersister persister = this.PageStatePersister;
1605 if (persister == null)
1607 Pair pair = viewState as Pair;
1609 persister.ViewState = pair.First;
1610 persister.ControlState = pair.Second;
1612 persister.ViewState = viewState;
1616 internal string RawViewState {
1618 NameValueCollection postdata = _requestValueCollection;
1620 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1623 if (view_state == "")
1628 set { _savedViewState = value; }
1632 protected virtual PageStatePersister PageStatePersister {
1634 if (page_state_persister == null && PageAdapter != null)
1635 page_state_persister = PageAdapter.GetStatePersister();
1636 if (page_state_persister == null)
1637 page_state_persister = new HiddenFieldPageStatePersister (this);
1638 return page_state_persister;
1642 [EditorBrowsable (EditorBrowsableState.Advanced)]
1643 protected virtual object LoadPageStateFromPersistenceMedium ()
1645 PageStatePersister persister = this.PageStatePersister;
1646 if (persister == null)
1649 return new Pair (persister.ViewState, persister.ControlState);
1652 internal void LoadPageViewState ()
1654 Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
1655 if (sState != null) {
1656 if (allow_load || isCrossPagePostBack) {
1657 LoadPageControlState (sState.Second);
1659 Pair vsr = sState.First as Pair;
1661 LoadViewStateRecursive (vsr.First);
1662 _requiresPostBackCopy = vsr.Second as ArrayList;
1668 internal void SavePageViewState ()
1670 if (!handleViewState)
1673 object controlState = SavePageControlState ();
1675 object viewState = null;
1677 if (EnableViewState)
1678 viewState = SaveViewStateRecursive ();
1680 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1681 if (viewState != null || reqPostback != null)
1682 vsr = new Pair (viewState, reqPostback);
1684 Pair pair = new Pair ();
1686 pair.Second = controlState;
1687 if (pair.First == null && pair.Second == null)
1688 SavePageStateToPersistenceMedium (null);
1690 SavePageStateToPersistenceMedium (pair);
1694 public virtual void Validate ()
1696 is_validated = true;
1697 ValidateCollection (_validators);
1700 internal bool AreValidatorsUplevel ()
1702 return AreValidatorsUplevel (String.Empty);
1705 internal bool AreValidatorsUplevel (string valGroup)
1707 bool uplevel = false;
1709 foreach (IValidator v in Validators) {
1710 BaseValidator bv = v as BaseValidator;
1714 if (valGroup != bv.ValidationGroup)
1716 if (bv.GetRenderUplevel()) {
1725 bool ValidateCollection (ValidatorCollection validators)
1727 if (validators == null || validators.Count == 0)
1730 bool all_valid = true;
1731 foreach (IValidator v in validators){
1733 if (v.IsValid == false)
1740 [EditorBrowsable (EditorBrowsableState.Advanced)]
1741 public virtual void VerifyRenderingInServerForm (Control control)
1743 if (Context == null)
1748 throw new HttpException ("Control '" +
1751 control.GetType ().Name +
1752 "' must be placed inside a form tag with runat=server.");
1755 protected override void FrameworkInitialize ()
1757 base.FrameworkInitialize ();
1758 InitializeStyleSheet ();
1762 public ClientScriptManager ClientScript {
1763 get { return scriptManager; }
1766 internal static readonly object InitCompleteEvent = new object ();
1767 internal static readonly object LoadCompleteEvent = new object ();
1768 internal static readonly object PreInitEvent = new object ();
1769 internal static readonly object PreLoadEvent = new object ();
1770 internal static readonly object PreRenderCompleteEvent = new object ();
1771 internal static readonly object SaveStateCompleteEvent = new object ();
1773 const int initcomplete_mask = 1;
1774 const int loadcomplete_mask = 1 << 1;
1775 const int preinit_mask = 1 << 2;
1776 const int preload_mask = 1 << 3;
1777 const int prerendercomplete_mask = 1 << 4;
1778 const int savestatecomplete_mask = 1 << 5;
1780 [EditorBrowsable (EditorBrowsableState.Advanced)]
1781 public event EventHandler InitComplete {
1783 event_mask |= initcomplete_mask;
1784 Events.AddHandler (InitCompleteEvent, value);
1786 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1789 [EditorBrowsable (EditorBrowsableState.Advanced)]
1790 public event EventHandler LoadComplete {
1792 event_mask |= loadcomplete_mask;
1793 Events.AddHandler (LoadCompleteEvent, value);
1795 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1798 public event EventHandler PreInit {
1800 event_mask |= preinit_mask;
1801 Events.AddHandler (PreInitEvent, value);
1803 remove { Events.RemoveHandler (PreInitEvent, value); }
1806 [EditorBrowsable (EditorBrowsableState.Advanced)]
1807 public event EventHandler PreLoad {
1809 event_mask |= preload_mask;
1810 Events.AddHandler (PreLoadEvent, value);
1812 remove { Events.RemoveHandler (PreLoadEvent, value); }
1815 [EditorBrowsable (EditorBrowsableState.Advanced)]
1816 public event EventHandler PreRenderComplete {
1818 event_mask |= prerendercomplete_mask;
1819 Events.AddHandler (PreRenderCompleteEvent, value);
1821 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
1824 [EditorBrowsable (EditorBrowsableState.Advanced)]
1825 public event EventHandler SaveStateComplete {
1827 event_mask |= savestatecomplete_mask;
1828 Events.AddHandler (SaveStateCompleteEvent, value);
1830 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
1833 protected virtual void OnInitComplete (EventArgs e)
1835 if ((event_mask & initcomplete_mask) != 0) {
1836 EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
1837 if (eh != null) eh (this, e);
1841 protected virtual void OnLoadComplete (EventArgs e)
1843 if ((event_mask & loadcomplete_mask) != 0) {
1844 EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
1845 if (eh != null) eh (this, e);
1849 protected virtual void OnPreInit (EventArgs e)
1851 if ((event_mask & preinit_mask) != 0) {
1852 EventHandler eh = (EventHandler) (Events [PreInitEvent]);
1853 if (eh != null) eh (this, e);
1857 protected virtual void OnPreLoad (EventArgs e)
1859 if ((event_mask & preload_mask) != 0) {
1860 EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
1861 if (eh != null) eh (this, e);
1865 protected virtual void OnPreRenderComplete (EventArgs e)
1867 if ((event_mask & prerendercomplete_mask) != 0) {
1868 EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
1869 if (eh != null) eh (this, e);
1874 if (!Form.DetermineRenderUplevel ())
1877 string defaultButtonId = Form.DefaultButton;
1878 /* figure out if we have some control we're going to focus */
1879 if (String.IsNullOrEmpty (_focusedControlID)) {
1880 _focusedControlID = Form.DefaultFocus;
1881 if (String.IsNullOrEmpty (_focusedControlID))
1882 _focusedControlID = defaultButtonId;
1885 if (!String.IsNullOrEmpty (_focusedControlID)) {
1886 ClientScript.RegisterWebFormClientScript ();
1888 ClientScript.RegisterStartupScript (
1890 "HtmlForm-DefaultButton-StartupScript",
1891 "\n" + WebFormScriptReference + ".WebForm_AutoFocus('" + _focusedControlID + "');\n", true);
1894 if (Form.SubmitDisabledControls && _hasEnabledControlArray) {
1895 ClientScript.RegisterWebFormClientScript ();
1897 ClientScript.RegisterOnSubmitStatement (
1899 "HtmlForm-SubmitDisabledControls-SubmitStatement",
1900 WebFormScriptReference + ".WebForm_ReEnableControls();");
1904 internal void RegisterEnabledControl (Control control)
1906 if (Form == null || !Page.Form.SubmitDisabledControls || !Page.Form.DetermineRenderUplevel ())
1908 _hasEnabledControlArray = true;
1909 Page.ClientScript.RegisterArrayDeclaration (EnabledControlArrayID, String.Concat ("'", control.ClientID, "'"));
1912 protected virtual void OnSaveStateComplete (EventArgs e)
1914 if ((event_mask & savestatecomplete_mask) != 0) {
1915 EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
1916 if (eh != null) eh (this, e);
1920 public HtmlForm Form {
1921 get { return _form; }
1924 internal void RegisterForm (HtmlForm form)
1929 public string ClientQueryString {
1930 get { return Request.UrlComponents.Query; }
1933 [BrowsableAttribute (false)]
1934 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1935 public Page PreviousPage {
1937 if (_doLoadPreviousPage) {
1938 _doLoadPreviousPage = false;
1939 LoadPreviousPageReference ();
1941 return previousPage;
1946 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1947 [BrowsableAttribute (false)]
1948 public bool IsCallback {
1949 get { return isCallback; }
1952 [BrowsableAttribute (false)]
1953 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1954 public bool IsCrossPagePostBack {
1955 get { return isCrossPagePostBack; }
1958 public new virtual char IdSeparator {
1960 //TODO: why override?
1961 return base.IdSeparator;
1965 string ProcessCallbackData ()
1967 ICallbackEventHandler target = GetCallbackTarget ();
1968 string callbackEventError = String.Empty;
1969 ProcessRaiseCallbackEvent (target, ref callbackEventError);
1970 return ProcessGetCallbackResult (target, callbackEventError);
1973 ICallbackEventHandler GetCallbackTarget ()
1975 string callbackTarget = _requestValueCollection [CallbackSourceID];
1976 if (callbackTarget == null || callbackTarget.Length == 0)
1977 throw new HttpException ("Callback target not provided.");
1979 Control targetControl = FindControl (callbackTarget, true);
1980 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
1982 throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
1986 void ProcessRaiseCallbackEvent (ICallbackEventHandler target, ref string callbackEventError)
1988 string callbackArgument = _requestValueCollection [CallbackArgumentID];
1991 target.RaiseCallbackEvent (callbackArgument);
1992 } catch (Exception ex) {
1993 callbackEventError = String.Concat ("e", RuntimeHelpers.DebuggingEnabled ? ex.ToString () : ex.Message);
1998 string ProcessGetCallbackResult (ICallbackEventHandler target, string callbackEventError)
2000 string callBackResult;
2002 callBackResult = target.GetCallbackResult ();
2003 } catch (Exception ex) {
2004 return String.Concat ("e", RuntimeHelpers.DebuggingEnabled ? ex.ToString () : ex.Message);
2007 string eventValidation = ClientScript.GetEventValidationStateFormatted ();
2008 return callbackEventError + (eventValidation == null ? "0" : eventValidation.Length.ToString ()) + "|" +
2009 eventValidation + callBackResult;
2012 [BrowsableAttribute (false)]
2013 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2014 public HtmlHead Header {
2015 get { return htmlHeader; }
2018 internal void SetHeader (HtmlHead header)
2020 htmlHeader = header;
2021 if (_title != null) {
2022 htmlHeader.Title = _title;
2027 protected bool AsyncMode {
2028 get { return asyncMode; }
2029 set { asyncMode = value; }
2032 public TimeSpan AsyncTimeout {
2033 get { return asyncTimeout; }
2034 set { asyncTimeout = value; }
2037 public bool IsAsync {
2038 get { return AsyncMode; }
2041 protected internal virtual string UniqueFilePathSuffix {
2043 if (String.IsNullOrEmpty (uniqueFilePathSuffix))
2044 uniqueFilePathSuffix = "__ufps=" + AppRelativeVirtualPath.GetHashCode ().ToString ("x");
2045 return uniqueFilePathSuffix;
2049 [MonoTODO ("Actually use the value in code.")]
2050 public int MaxPageStateFieldLength {
2051 get { return maxPageStateFieldLength; }
2052 set { maxPageStateFieldLength = value; }
2055 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
2057 AddOnPreRenderCompleteAsync (beginHandler, endHandler, null);
2060 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
2063 throw new InvalidOperationException ("AddOnPreRenderCompleteAsync called and Page.IsAsync == false");
2066 if (IsPrerendered) {
2067 throw new InvalidOperationException ("AddOnPreRenderCompleteAsync can only be called before and during PreRender.");
2070 if (beginHandler == null) {
2071 throw new ArgumentNullException ("beginHandler");
2074 if (endHandler == null) {
2075 throw new ArgumentNullException ("endHandler");
2078 RegisterAsyncTask (new PageAsyncTask (beginHandler, endHandler, null, state, false));
2081 List<PageAsyncTask> ParallelTasks {
2083 if (parallelTasks == null)
2084 parallelTasks = new List<PageAsyncTask>();
2085 return parallelTasks;
2089 List<PageAsyncTask> SerialTasks {
2091 if (serialTasks == null)
2092 serialTasks = new List<PageAsyncTask> ();
2097 public void RegisterAsyncTask (PageAsyncTask task)
2100 throw new ArgumentNullException ("task");
2102 if (task.ExecuteInParallel)
2103 ParallelTasks.Add (task);
2105 SerialTasks.Add (task);
2108 public void ExecuteRegisteredAsyncTasks ()
2110 if ((parallelTasks == null || parallelTasks.Count == 0) &&
2111 (serialTasks == null || serialTasks.Count == 0)){
2115 if (parallelTasks != null) {
2116 DateTime startExecution = DateTime.Now;
2117 List<PageAsyncTask> localParallelTasks = parallelTasks;
2118 parallelTasks = null; // Shouldn't execute tasks twice
2119 List<IAsyncResult> asyncResults = new List<IAsyncResult>();
2120 foreach (PageAsyncTask parallelTask in localParallelTasks) {
2121 IAsyncResult result = parallelTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), parallelTask.State);
2122 if (result.CompletedSynchronously)
2123 parallelTask.EndHandler (result);
2125 asyncResults.Add (result);
2128 if (asyncResults.Count > 0) {
2130 TimeSpan timeout = AsyncTimeout;
2131 long t1 = DateTime.Now.Ticks;
2132 bool signalled = true;
2133 for (int i = 0; i < asyncResults.Count; i++) {
2134 if (asyncResults [i].IsCompleted)
2138 signalled = asyncResults [i].AsyncWaitHandle.WaitOne (timeout, false);
2141 long t2 = DateTime.Now.Ticks;
2142 timeout = AsyncTimeout - TimeSpan.FromTicks (t2 - t1);
2143 if (timeout.Ticks <= 0)
2146 localParallelTasks [i].TimeoutHandler (asyncResults [i]);
2149 WaitHandle [] waitArray = new WaitHandle [asyncResults.Count];
2151 for (i = 0; i < asyncResults.Count; i++) {
2152 waitArray [i] = asyncResults [i].AsyncWaitHandle;
2155 bool allSignalled = WaitHandle.WaitAll (waitArray, AsyncTimeout, false);
2156 if (!allSignalled) {
2157 for (i = 0; i < asyncResults.Count; i++) {
2158 if (!asyncResults [i].IsCompleted) {
2159 localParallelTasks [i].TimeoutHandler (asyncResults [i]);
2165 DateTime endWait = DateTime.Now;
2166 TimeSpan elapsed = endWait - startExecution;
2167 if (elapsed <= AsyncTimeout)
2168 AsyncTimeout -= elapsed;
2170 AsyncTimeout = TimeSpan.FromTicks(0);
2173 if (serialTasks != null) {
2174 List<PageAsyncTask> localSerialTasks = serialTasks;
2175 serialTasks = null; // Shouldn't execute tasks twice
2176 foreach (PageAsyncTask serialTask in localSerialTasks) {
2177 DateTime startExecution = DateTime.Now;
2179 IAsyncResult result = serialTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), serialTask);
2180 if (result.CompletedSynchronously)
2181 serialTask.EndHandler (result);
2183 bool done = result.AsyncWaitHandle.WaitOne (AsyncTimeout, false);
2184 if (!done && !result.IsCompleted) {
2185 serialTask.TimeoutHandler (result);
2188 DateTime endWait = DateTime.Now;
2189 TimeSpan elapsed = endWait - startExecution;
2190 if (elapsed <= AsyncTimeout)
2191 AsyncTimeout -= elapsed;
2193 AsyncTimeout = TimeSpan.FromTicks (0);
2196 AsyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
2199 void EndAsyncTaskCallback (IAsyncResult result)
2201 PageAsyncTask task = (PageAsyncTask)result.AsyncState;
2202 task.EndHandler (result);
2205 public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
2207 Type htmlTextWriterType = typeof (HtmlTextWriter);
2209 if (!htmlTextWriterType.IsAssignableFrom (writerType)) {
2210 throw new HttpException (String.Format ("Type '{0}' cannot be assigned to HtmlTextWriter", writerType.FullName));
2213 ConstructorInfo constructor = writerType.GetConstructor (new Type [] { typeof (TextWriter) });
2214 if (constructor == null) {
2215 throw new HttpException (String.Format ("Type '{0}' does not have a consturctor that takes a TextWriter as parameter", writerType.FullName));
2218 return (HtmlTextWriter) Activator.CreateInstance(writerType, tw);
2221 public ViewStateEncryptionMode ViewStateEncryptionMode {
2222 get { return viewStateEncryptionMode; }
2223 set { viewStateEncryptionMode = value; }
2226 public void RegisterRequiresViewStateEncryption ()
2228 controlRegisteredForViewStateEncryption = true;
2231 static byte [] AES_IV = null;
2232 static byte [] TripleDES_IV = null;
2233 static object locker = new object ();
2234 static bool isEncryptionInitialized = false;
2236 static void InitializeEncryption ()
2238 if (isEncryptionInitialized)
2242 if (isEncryptionInitialized)
2245 string iv_string = "0BA48A9E-736D-40f8-954B-B2F62241F282";
2246 AES_IV = new byte [16];
2247 TripleDES_IV = new byte [8];
2250 for (i = 0; i < AES_IV.Length; i++) {
2251 AES_IV [i] = (byte) iv_string [i];
2254 for (i = 0; i < TripleDES_IV.Length; i++) {
2255 TripleDES_IV [i] = (byte) iv_string [i];
2258 isEncryptionInitialized = true;
2262 internal ICryptoTransform GetCryptoTransform (CryptoStreamMode cryptoStreamMode)
2264 ICryptoTransform transform = null;
2265 MachineKeySection config = (MachineKeySection) WebConfigurationManager.GetSection (machineKeyConfigPath);
2266 byte [] vk = MachineKeySectionUtils.ValidationKeyBytes (config);
2268 switch (config.Validation) {
2269 case MachineKeyValidation.SHA1:
2270 transform = SHA1.Create ();
2273 case MachineKeyValidation.MD5:
2274 transform = MD5.Create ();
2277 case MachineKeyValidation.AES:
2278 InitializeEncryption ();
2279 if (cryptoStreamMode == CryptoStreamMode.Read){
2280 transform = Rijndael.Create().CreateDecryptor(vk, AES_IV);
2282 transform = Rijndael.Create().CreateEncryptor(vk, AES_IV);
2286 case MachineKeyValidation.TripleDES:
2287 InitializeEncryption ();
2288 if (cryptoStreamMode == CryptoStreamMode.Read){
2289 transform = TripleDES.Create().CreateDecryptor(vk, TripleDES_IV);
2291 transform = TripleDES.Create().CreateEncryptor(vk, TripleDES_IV);
2299 internal bool NeedViewStateEncryption {
2301 return (ViewStateEncryptionMode == ViewStateEncryptionMode.Always ||
2302 (ViewStateEncryptionMode == ViewStateEncryptionMode.Auto &&
2303 controlRegisteredForViewStateEncryption));
2308 void ApplyMasterPage ()
2310 if (masterPageFile != null && masterPageFile.Length > 0) {
2311 ArrayList appliedMasterPageFiles = new ArrayList ();
2313 if (Master != null) {
2314 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
2318 Controls.Add (Master);
2323 [DefaultValueAttribute ("")]
2324 public virtual string MasterPageFile {
2325 get { return masterPageFile; }
2327 masterPageFile = value;
2332 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2333 [BrowsableAttribute (false)]
2334 public MasterPage Master {
2336 if (Context == null || String.IsNullOrEmpty (masterPageFile))
2339 if (masterPage == null)
2340 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
2346 public void SetFocus (string clientID)
2348 if (String.IsNullOrEmpty (clientID))
2349 throw new ArgumentNullException ("control");
2352 throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
2355 throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
2357 _focusedControlID = clientID;
2360 public void SetFocus (Control control)
2362 if (control == null)
2363 throw new ArgumentNullException ("control");
2365 SetFocus (control.ClientID);
2368 [EditorBrowsable (EditorBrowsableState.Advanced)]
2369 public void RegisterRequiresControlState (Control control)
2371 if (control == null)
2372 throw new ArgumentNullException ("control");
2374 if (RequiresControlState (control))
2377 if (requireStateControls == null)
2378 requireStateControls = new List <Control> ();
2379 requireStateControls.Add (control);
2380 int n = requireStateControls.Count - 1;
2382 if (_savedControlState == null || n >= _savedControlState.Length)
2385 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2386 if (parent.IsChildControlStateCleared)
2389 object state = _savedControlState [n];
2391 control.LoadControlState (state);
2394 public bool RequiresControlState (Control control)
2396 if (requireStateControls == null)
2398 return requireStateControls.Contains (control);
2401 [EditorBrowsable (EditorBrowsableState.Advanced)]
2402 public void UnregisterRequiresControlState (Control control)
2404 if (requireStateControls != null)
2405 requireStateControls.Remove (control);
2408 public ValidatorCollection GetValidators (string validationGroup)
2410 if (validationGroup == String.Empty)
2411 validationGroup = null;
2413 ValidatorCollection col = new ValidatorCollection ();
2414 if (_validators == null)
2417 foreach (IValidator v in _validators)
2418 if (BelongsToGroup(v, validationGroup))
2424 bool BelongsToGroup(IValidator v, string validationGroup)
2426 BaseValidator validator = v as BaseValidator;
2427 if (validationGroup == null)
2428 return validator == null || String.IsNullOrEmpty (validator.ValidationGroup);
2430 return validator != null && validator.ValidationGroup == validationGroup;
2433 public virtual void Validate (string validationGroup)
2435 is_validated = true;
2436 ValidateCollection (GetValidators (validationGroup));
2439 object SavePageControlState ()
2441 int count = requireStateControls == null ? 0 : requireStateControls.Count;
2446 object[] controlStates = new object [count];
2447 object[] adapterState = new object [count];
2449 ControlAdapter adapter;
2450 bool allNull = true;
2451 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
2453 for (int n = 0; n < count; n++) {
2454 control = requireStateControls [n];
2455 state = controlStates [n] = control.SaveControlState ();
2460 trace.SaveControlState (control, state);
2462 adapter = control.Adapter;
2463 if (adapter != null) {
2464 adapterState [n] = adapter.SaveAdapterControlState ();
2465 if (adapterState [n] != null) allNull = false;
2472 return new Pair (controlStates, adapterState);
2475 void LoadPageControlState (object data)
2477 _savedControlState = null;
2478 if (data == null) return;
2479 Pair statePair = (Pair)data;
2480 _savedControlState = (object[]) statePair.First;
2481 object[] adapterState = (object[]) statePair.Second;
2483 if (requireStateControls == null) return;
2485 int min = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2486 for (int n=0; n < min; n++) {
2487 Control ctl = (Control) requireStateControls [n];
2488 ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2489 if (ctl.Adapter != null)
2490 ctl.Adapter.LoadAdapterControlState (adapterState != null ? adapterState [n] : null);
2494 void LoadPreviousPageReference ()
2496 if (_requestValueCollection != null) {
2497 string prevPage = _requestValueCollection [PreviousPageID];
2498 if (prevPage != null) {
2500 if (getFacesContext () != null) {
2501 IHttpHandler handler = Context.ApplicationInstance.GetHandler (Context, prevPage);
2502 Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
2503 if (_context.Items.Contains (CrossPagePostBack)) {
2504 previousPage = (Page) _context.Items [CrossPagePostBack];
2505 _context.Items.Remove (CrossPagePostBack);
2510 IHttpHandler handler;
2511 handler = BuildManager.CreateInstanceFromVirtualPath (prevPage, typeof (IHttpHandler)) as IHttpHandler;
2512 previousPage = (Page) handler;
2513 previousPage.isCrossPagePostBack = true;
2514 Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
2520 Hashtable contentTemplates;
2521 [EditorBrowsable (EditorBrowsableState.Never)]
2522 protected internal void AddContentTemplate (string templateName, ITemplate template)
2524 if (contentTemplates == null)
2525 contentTemplates = new Hashtable ();
2526 contentTemplates [templateName] = template;
2529 PageTheme _pageTheme;
2530 internal PageTheme PageTheme {
2531 get { return _pageTheme; }
2534 PageTheme _styleSheetPageTheme;
2535 internal PageTheme StyleSheetPageTheme {
2536 get { return _styleSheetPageTheme; }
2541 internal void PushDataItemContext (object o) {
2542 if (dataItemCtx == null)
2543 dataItemCtx = new Stack ();
2545 dataItemCtx.Push (o);
2548 internal void PopDataItemContext () {
2549 if (dataItemCtx == null)
2550 throw new InvalidOperationException ();
2555 public object GetDataItem() {
2556 if (dataItemCtx == null || dataItemCtx.Count == 0)
2557 throw new InvalidOperationException ("No data item");
2559 return dataItemCtx.Peek ();
2562 protected internal override void OnInit (EventArgs e)
2566 ArrayList themes = new ArrayList();
2568 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2569 themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2571 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2572 themes.AddRange (PageTheme.GetStyleSheets ());
2574 if (themes.Count > 0 && Header == null)
2575 throw new InvalidOperationException ("Using themed css files requires a header control on the page.");
2577 foreach (string lss in themes) {
2578 HtmlLink hl = new HtmlLink ();
2580 hl.Attributes["type"] = "text/css";
2581 hl.Attributes["rel"] = "stylesheet";
2582 Header.Controls.Add (hl);
2586 [MonoTODO ("Not implemented. Only used by .net aspx parser")]
2587 protected object GetWrappedFileDependencies (string [] list)
2592 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2593 protected virtual void InitializeCulture ()
2597 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2598 protected internal void AddWrappedFileDependencies (object virtualFileDependencies)