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)
9 // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
10 // Copyright (C) 2003,2005 Novell, Inc (http://www.novell.com)
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
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;
40 using System.Security.Cryptography;
41 using System.Security.Permissions;
42 using System.Security.Principal;
44 using System.Threading;
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;
53 using System.Web.UI.Adapters;
56 namespace System.Web.UI
59 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
60 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
62 [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
64 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
67 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
69 [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
71 public partial class Page : TemplateControl, IHttpHandler
74 private PageLifeCycle _lifeCycle = PageLifeCycle.Unknown;
75 private bool _eventValidation = true;
76 private object [] _savedControlState;
77 private bool _doLoadPreviousPage;
78 string _focusedControlID;
80 private bool _viewState = true;
81 private bool _viewStateMac;
82 private string _errorPage;
83 private bool is_validated;
84 private bool _smartNavigation;
85 private int _transactionMode;
86 private HttpContext _context;
87 private ValidatorCollection _validators;
88 private bool renderingForm;
89 private string _savedViewState;
90 private ArrayList _requiresPostBack;
91 private ArrayList _requiresPostBackCopy;
92 private ArrayList requiresPostDataChanged;
93 private IPostBackEventHandler requiresRaiseEvent;
94 private NameValueCollection secondPostData;
95 private bool requiresPostBackScript;
96 private bool postBackScriptRendered;
98 string viewStateUserKey;
99 NameValueCollection _requestValueCollection;
101 ClientScriptManager scriptManager;
102 bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
103 PageStatePersister page_state_persister;
105 [EditorBrowsable (EditorBrowsableState.Never)]
111 const string postEventArgumentID = "__EVENTARGUMENT";
113 [EditorBrowsable (EditorBrowsableState.Never)]
119 const string postEventSourceID = "__EVENTTARGET";
122 const string ScrollPositionXID = "__SCROLLPOSITIONX";
123 const string ScrollPositionYID = "__SCROLLPOSITIONY";
127 internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
128 internal const string CallbackSourceID = "__CALLBACKTARGET";
129 internal const string PreviousPageID = "__PREVIOUSPAGE";
133 MasterPage masterPage;
134 string masterPageFile;
137 bool isCrossPagePostBack;
140 ArrayList requireStateControls;
141 Hashtable _validatorsByGroup;
146 string _styleSheetTheme;
149 bool _maintainScrollPositionOnPostBack;
155 scriptManager = new ClientScriptManager (this);
164 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
166 public HttpApplicationState Application
169 if (_context == null)
171 return _context.Application;
175 [EditorBrowsable (EditorBrowsableState.Never)]
176 protected bool AspCompatMode
179 get { return false; }
181 set { throw new NotImplementedException (); }
184 [EditorBrowsable (EditorBrowsableState.Never)]
186 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
187 [BrowsableAttribute (false)]
190 get { return Response.BufferOutput; }
191 set { Response.BufferOutput = value; }
194 protected bool Buffer
196 set { Response.BufferOutput = value; }
200 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
205 if (_context == null)
206 throw new HttpException ("No cache available without a context.");
207 return _context.Cache;
212 [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
214 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
215 [Browsable (false), DefaultValue ("")]
216 [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
217 public string ClientTarget
219 get { return (clientTarget == null) ? "" : clientTarget; }
221 clientTarget = value;
227 [EditorBrowsable (EditorBrowsableState.Never)]
229 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
230 [BrowsableAttribute (false)]
233 get { return Response.ContentEncoding.CodePage; }
234 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
237 protected int CodePage
239 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
243 [EditorBrowsable (EditorBrowsableState.Never)]
245 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
246 [BrowsableAttribute (false)]
247 public string ContentType
249 get { return Response.ContentType; }
250 set { Response.ContentType = value; }
253 protected string ContentType
255 set { Response.ContentType = value; }
259 protected override HttpContext Context
262 if (_context == null)
263 return HttpContext.Current;
270 [EditorBrowsable (EditorBrowsableState.Advanced)]
271 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
272 [BrowsableAttribute (false)]
273 public string Culture
275 get { return Thread.CurrentThread.CurrentCulture.Name; }
276 set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
279 [EditorBrowsable (EditorBrowsableState.Never)]
280 protected string Culture
282 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
287 public virtual bool EnableEventValidation {
288 get { return _eventValidation; }
290 if (_lifeCycle > PageLifeCycle.Init)
291 throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
292 _eventValidation = value;
296 internal PageLifeCycle LifeCycle {
297 get { return _lifeCycle; }
302 public override bool EnableViewState
304 get { return _viewState; }
305 set { _viewState = value; }
309 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
310 [BrowsableAttribute (false)]
312 [EditorBrowsable (EditorBrowsableState.Never)]
318 bool EnableViewStateMac
320 get { return _viewStateMac; }
321 set { _viewStateMac = value; }
325 internal bool EnableViewStateMacInternal {
326 get { return _viewStateMac; }
327 set { _viewStateMac = value; }
331 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
332 [Browsable (false), DefaultValue ("")]
333 [WebSysDescription ("The URL of a page used for error redirection.")]
334 public string ErrorPage
336 get { return _errorPage; }
339 if (_context != null)
340 _context.ErrorPage = value;
347 [EditorBrowsable (EditorBrowsableState.Never)]
348 protected ArrayList FileDependencies
351 if (Response != null)
352 Response.AddFileDependencies (value);
358 [EditorBrowsable (EditorBrowsableState.Never)]
360 public override string ID
362 get { return base.ID; }
363 set { base.ID = value; }
366 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
368 public bool IsPostBack
374 return _requestValueCollection != null;
379 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
380 public bool IsReusable {
381 get { return false; }
384 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
386 public bool IsValid {
389 throw new HttpException (Locale.GetText ("Page hasn't been validated."));
392 foreach (IValidator val in Validators)
397 return ValidateCollection (_validators);
402 public IDictionary Items {
405 items = new Hashtable ();
411 [EditorBrowsable (EditorBrowsableState.Never)]
413 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
414 [BrowsableAttribute (false)]
416 get { return Thread.CurrentThread.CurrentCulture.LCID; }
417 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
421 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
427 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
428 public bool MaintainScrollPositionOnPostBack {
429 get { return _maintainScrollPositionOnPostBack; }
430 set { _maintainScrollPositionOnPostBack = value; }
435 public PageAdapter PageAdapter {
437 return (PageAdapter)Adapter;
443 internal string theForm {
450 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
452 public HttpRequest Request
455 if (_context != null)
456 return _context.Request;
458 throw new HttpException("Request is not available without context");
462 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
464 public HttpResponse Response
467 if (_context != null)
468 return _context.Response;
470 throw new HttpException ("Response is not available without context");
474 [EditorBrowsable (EditorBrowsableState.Never)]
476 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
477 [BrowsableAttribute (false)]
478 public string ResponseEncoding
480 get { return Response.ContentEncoding.WebName; }
481 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
484 protected string ResponseEncoding
486 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
490 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
492 public HttpServerUtility Server
495 return Context.Server;
499 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
501 public virtual HttpSessionState Session
504 if (_context == null)
505 _context = HttpContext.Current;
507 if (_context == null)
508 throw new HttpException ("Session is not available without context");
510 if (_context.Session == null)
511 throw new HttpException ("Session state can only be used " +
512 "when enableSessionState is set to true, either " +
513 "in a configuration file or in the Page directive.");
515 return _context.Session;
520 [FilterableAttribute (false)]
524 public bool SmartNavigation
526 get { return _smartNavigation; }
527 set { _smartNavigation = value; }
531 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
534 public virtual string StyleSheetTheme {
535 get { return _styleSheetTheme; }
536 set { _styleSheetTheme = value; }
540 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
541 public virtual string Theme {
542 get { return _theme; }
543 set { _theme = value; }
546 void InitializeStyleSheet ()
548 if (_styleSheetTheme == null) {
549 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
551 _styleSheetTheme = ps.StyleSheetTheme;
553 if (_styleSheetTheme != null && _styleSheetTheme != "")
554 _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, _context);
557 void InitializeTheme ()
559 if (_theme == null) {
560 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
564 if (_theme != null && _theme != "") {
565 _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, _context);
566 _pageTheme.SetPage (this);
575 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
576 public string Title {
579 return htmlHeader.Title;
583 if (htmlHeader != null)
584 htmlHeader.Title = value;
591 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
593 public TraceContext Trace
595 get { return Context.Trace; }
598 [EditorBrowsable (EditorBrowsableState.Never)]
600 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
601 [BrowsableAttribute (false)]
602 public bool TraceEnabled
604 get { return Trace.IsEnabled; }
605 set { Trace.IsEnabled = value; }
608 protected bool TraceEnabled
610 set { Trace.IsEnabled = value; }
614 [EditorBrowsable (EditorBrowsableState.Never)]
616 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
617 [BrowsableAttribute (false)]
618 public TraceMode TraceModeValue
620 get { return Trace.TraceMode; }
621 set { Trace.TraceMode = value; }
624 protected TraceMode TraceModeValue
626 set { Trace.TraceMode = value; }
630 [EditorBrowsable (EditorBrowsableState.Never)]
631 protected int TransactionMode
634 get { return _transactionMode; }
636 set { _transactionMode = value; }
641 // This method is here just to remove the warning about "_transactionMode" not being
642 // used. We probably will use it internally at some point.
644 internal int GetTransactionMode ()
646 return _transactionMode;
651 [EditorBrowsable (EditorBrowsableState.Advanced)]
652 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
653 [BrowsableAttribute (false)]
654 public string UICulture
656 get { return Thread.CurrentThread.CurrentUICulture.Name; }
657 set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
660 [EditorBrowsable (EditorBrowsableState.Never)]
661 protected string UICulture
663 set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
667 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
669 public IPrincipal User
671 get { return Context.User; }
674 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
676 public ValidatorCollection Validators
679 if (_validators == null)
680 _validators = new ValidatorCollection ();
685 [MonoTODO ("Use this when encrypting/decrypting ViewState")]
687 public string ViewStateUserKey {
688 get { return viewStateUserKey; }
689 set { viewStateUserKey = value; }
693 public override bool Visible
695 get { return base.Visible; }
696 set { base.Visible = value; }
704 CultureInfo GetPageCulture (string culture, CultureInfo deflt)
708 CultureInfo ret = null;
709 if (culture.StartsWith ("auto")) {
710 string[] languages = Request.UserLanguages;
712 if (languages != null && languages.Length > 0)
713 ret = new CultureInfo (languages[0]);
720 ret = new CultureInfo (culture);
726 [EditorBrowsable (EditorBrowsableState.Never)]
727 protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
731 throw new NotImplementedException ();
734 [EditorBrowsable (EditorBrowsableState.Never)]
735 protected void AspCompatEndProcessRequest (IAsyncResult result)
737 throw new NotImplementedException ();
740 [EditorBrowsable (EditorBrowsableState.Advanced)]
741 protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
743 return new HtmlTextWriter (tw);
746 [EditorBrowsable (EditorBrowsableState.Never)]
747 public void DesignerInitialize ()
749 InitRecursive (null);
752 [EditorBrowsable (EditorBrowsableState.Advanced)]
753 protected virtual NameValueCollection DeterminePostBackMode ()
755 if (_context == null)
758 HttpRequest req = _context.Request;
762 NameValueCollection coll = null;
763 if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture))
766 else if (IsPortletRender && req.Form ["__VIEWSTATE"] != null)
770 coll = req.QueryString;
772 WebROCollection c = (WebROCollection) coll;
773 allow_load = !c.GotID;
775 c.ID = GetTypeHashCode ();
777 allow_load = (c.ID == GetTypeHashCode ());
779 if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
786 public override Control FindControl (string id) {
790 return base.FindControl (id);
797 [EditorBrowsable (EditorBrowsableState.Advanced)]
798 public string GetPostBackClientEvent (Control control, string argument)
800 return scriptManager.GetPostBackEventReference (control, argument);
806 [EditorBrowsable (EditorBrowsableState.Advanced)]
807 public string GetPostBackClientHyperlink (Control control, string argument)
809 return scriptManager.GetPostBackClientHyperlink (control, argument);
815 [EditorBrowsable (EditorBrowsableState.Advanced)]
816 public string GetPostBackEventReference (Control control)
818 return scriptManager.GetPostBackEventReference (control, "");
824 [EditorBrowsable (EditorBrowsableState.Advanced)]
825 public string GetPostBackEventReference (Control control, string argument)
827 return scriptManager.GetPostBackEventReference (control, argument);
830 internal void RequiresPostBackScript ()
832 requiresPostBackScript = true;
835 ClientScript.RegisterWebFormClientScript ();
839 [EditorBrowsable (EditorBrowsableState.Never)]
840 public virtual int GetTypeHashCode ()
846 [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
847 protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
849 if (cacheSettings.Enabled)
850 InitOutputCache(cacheSettings.Duration,
851 cacheSettings.VaryByHeader,
852 cacheSettings.VaryByCustom,
853 cacheSettings.Location,
854 cacheSettings.VaryByParam);
858 [EditorBrowsable (EditorBrowsableState.Never)]
859 protected virtual void InitOutputCache (int duration,
862 OutputCacheLocation location,
865 HttpCachePolicy cache = _context.Response.Cache;
866 bool set_vary = false;
869 case OutputCacheLocation.Any:
870 cache.SetCacheability (HttpCacheability.Public);
871 cache.SetMaxAge (new TimeSpan (0, 0, duration));
872 cache.SetLastModified (_context.Timestamp);
875 case OutputCacheLocation.Client:
876 cache.SetCacheability (HttpCacheability.Private);
877 cache.SetMaxAge (new TimeSpan (0, 0, duration));
878 cache.SetLastModified (_context.Timestamp);
880 case OutputCacheLocation.Downstream:
881 cache.SetCacheability (HttpCacheability.Public);
882 cache.SetMaxAge (new TimeSpan (0, 0, duration));
883 cache.SetLastModified (_context.Timestamp);
885 case OutputCacheLocation.Server:
886 cache.SetCacheability (HttpCacheability.Server);
889 case OutputCacheLocation.None:
894 if (varyByCustom != null)
895 cache.SetVaryByCustom (varyByCustom);
897 if (varyByParam != null && varyByParam.Length > 0) {
898 string[] prms = varyByParam.Split (';');
899 foreach (string p in prms)
900 cache.VaryByParams [p.Trim ()] = true;
901 cache.VaryByParams.IgnoreParams = false;
903 cache.VaryByParams.IgnoreParams = true;
906 if (varyByHeader != null && varyByHeader.Length > 0) {
907 string[] hdrs = varyByHeader.Split (';');
908 foreach (string h in hdrs)
909 cache.VaryByHeaders [h.Trim ()] = true;
913 cache.Duration = duration;
914 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
920 [EditorBrowsable (EditorBrowsableState.Advanced)]
922 public bool IsClientScriptBlockRegistered (string key)
924 return scriptManager.IsClientScriptBlockRegistered (key);
930 [EditorBrowsable (EditorBrowsableState.Advanced)]
932 public bool IsStartupScriptRegistered (string key)
934 return scriptManager.IsStartupScriptRegistered (key);
937 public string MapPath (string virtualPath)
939 return Request.MapPath (virtualPath);
943 protected internal override void Render (HtmlTextWriter writer) {
944 if (MaintainScrollPositionOnPostBack) {
945 RequiresPostBackScript ();
947 string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
949 ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
951 ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
952 ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
954 StringBuilder script = new StringBuilder ();
955 script.AppendLine ("<script type=\"text/javascript\">");
956 script.AppendLine ("<!--");
957 script.AppendLine (theForm + ".oldSubmit = " + theForm + ".submit;");
958 script.AppendLine (theForm + ".submit = WebForm_SaveScrollPositionSubmit;");
959 script.AppendLine (theForm + ".oldOnSubmit = " + theForm + ".onsubmit;");
960 script.AppendLine (theForm + ".onsubmit = WebForm_SaveScrollPositionOnSubmit;");
962 script.AppendLine (theForm + ".oldOnLoad = window.onload;");
963 script.AppendLine ("window.onload = function () { WebForm_RestoreScrollPosition (" + theForm + "); };");
965 script.AppendLine ("// -->");
966 script.AppendLine ("</script>");
968 ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
970 base.Render (writer);
974 private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
976 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
977 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
979 writer.WriteLine ("<script language=\"javascript\">");
980 writer.WriteLine ("<!--");
982 writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
983 writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
984 writer.WriteLine ("\t{0}.isAspForm = true;", theForm);
985 writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
986 writer.WriteLine ("\t\tif(document.ValidatorOnSubmit && !ValidatorOnSubmit()) return;");
987 writer.WriteLine ("\t\tvar myForm = " + theForm + ";");
989 writer.WriteLine ("\t\tif(document.WebForm_GetFormFromCtrl) myForm = WebForm_GetFormFromCtrl (eventTarget);");
991 writer.WriteLine ("\t\tmyForm.{0}.value = eventTarget;", postEventSourceID);
992 writer.WriteLine ("\t\tmyForm.{0}.value = eventArgument;", postEventArgumentID);
993 writer.WriteLine ("\t\tmyForm.submit();");
994 writer.WriteLine ("\t}");
995 writer.WriteLine ("// -->");
996 writer.WriteLine ("</script>");
999 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
1002 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
1004 renderingForm = true;
1005 writer.WriteLine ();
1007 if (handleViewState)
1008 scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
1010 scriptManager.WriteHiddenFields (writer);
1011 if (requiresPostBackScript) {
1012 RenderPostBackScript (writer, formUniqueID);
1013 postBackScriptRendered = true;
1015 scriptManager.WriteClientScriptIncludes (writer);
1016 scriptManager.WriteClientScriptBlocks (writer);
1019 internal IStateFormatter GetFormatter ()
1021 return new ObjectStateFormatter (this);
1024 internal string GetSavedViewState ()
1026 return _savedViewState;
1029 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1031 scriptManager.WriteArrayDeclares (writer);
1033 if (!postBackScriptRendered && requiresPostBackScript)
1034 RenderPostBackScript (writer, formUniqueID);
1037 scriptManager.SaveEventValidationState ();
1038 scriptManager.WriteExpandoAttributes (writer);
1040 scriptManager.WriteHiddenFields (writer);
1041 scriptManager.WriteClientScriptIncludes (writer);
1042 scriptManager.WriteStartupScriptBlocks (writer);
1043 renderingForm = false;
1044 postBackScriptRendered = false;
1047 private void ProcessPostData (NameValueCollection data, bool second)
1051 Hashtable used = new Hashtable ();
1052 foreach (string id in data.AllKeys){
1053 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
1056 string real_id = id;
1057 int dot = real_id.IndexOf ('.');
1059 real_id = real_id.Substring (0, dot);
1061 if (real_id == null || used.ContainsKey (real_id))
1064 used.Add (real_id, real_id);
1066 Control ctrl = FindControl (real_id);
1068 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1069 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1073 RegisterRequiresRaiseEvent (pbeh);
1077 if (pbdh.LoadPostData (real_id, data) == true) {
1078 if (requiresPostDataChanged == null)
1079 requiresPostDataChanged = new ArrayList ();
1080 requiresPostDataChanged.Add (pbdh);
1083 if (_requiresPostBackCopy != null)
1084 _requiresPostBackCopy.Remove (real_id);
1086 } else if (!second) {
1087 if (secondPostData == null)
1088 secondPostData = new NameValueCollection ();
1089 secondPostData.Add (real_id, data [id]);
1094 ArrayList list1 = null;
1095 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1096 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1097 foreach (string id in handlers) {
1098 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
1100 _requiresPostBackCopy.Remove (id);
1101 if (pbdh.LoadPostData (id, data)) {
1102 if (requiresPostDataChanged == null)
1103 requiresPostDataChanged = new ArrayList ();
1105 requiresPostDataChanged.Add (pbdh);
1107 } else if (!second) {
1109 list1 = new ArrayList ();
1114 _requiresPostBackCopy = second ? null : list1;
1116 secondPostData = null;
1119 [EditorBrowsable (EditorBrowsableState.Never)]
1120 #if NET_2_0 || TARGET_JVM
1121 public virtual void ProcessRequest (HttpContext context)
1123 public void ProcessRequest (HttpContext context)
1127 _lifeCycle = PageLifeCycle.Unknown;
1130 if (clientTarget != null)
1131 Request.ClientTarget = clientTarget;
1133 WireupAutomaticEvents ();
1134 //-- Control execution lifecycle in the docs
1136 // Save culture information because it can be modified in FrameworkInitialize()
1137 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
1138 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
1139 FrameworkInitialize ();
1140 context.ErrorPage = _errorPage;
1143 InternalProcessRequest ();
1144 } catch (ThreadAbortException) {
1145 // Do nothing, just ignore it by now.
1146 } catch (Exception e) {
1147 context.AddError (e); // OnError might access LastError
1148 OnError (EventArgs.Empty);
1149 context.ClearError (e);
1150 // We want to remove that error, as we're rethrowing to stop
1151 // further processing.
1152 Trace.Warn ("Unhandled Exception", e.ToString (), e);
1157 _lifeCycle = PageLifeCycle.Unload;
1160 UnloadRecursive (true);
1162 _lifeCycle = PageLifeCycle.End;
1165 if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
1166 Thread.CurrentThread.CurrentCulture = culture;
1168 if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
1169 Thread.CurrentThread.CurrentUICulture = uiculture;
1174 internal void ProcessCrossPagePostBack (HttpContext context)
1176 isCrossPagePostBack = true;
1177 ProcessRequest (context);
1181 void InternalProcessRequest ()
1183 _requestValueCollection = this.DeterminePostBackMode();
1186 _lifeCycle = PageLifeCycle.Start;
1187 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1188 if (_requestValueCollection != null) {
1189 if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1190 _doLoadPreviousPage = true;
1193 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1194 isPostBack = !isCallback;
1198 // if request was transfered from other page - track Prev. Page
1199 previousPage = _context.LastPage;
1200 _context.LastPage = this;
1202 _lifeCycle = PageLifeCycle.PreInit;
1203 OnPreInit (EventArgs.Empty);
1207 _lifeCycle = PageLifeCycle.Init;
1209 Trace.Write ("aspx.page", "Begin Init");
1210 InitRecursive (null);
1211 Trace.Write ("aspx.page", "End Init");
1214 _lifeCycle = PageLifeCycle.InitComplete;
1215 OnInitComplete (EventArgs.Empty);
1218 renderingForm = false;
1220 if (IsPostBack || IsCallback) {
1221 _lifeCycle = PageLifeCycle.PreLoad;
1222 if (_requestValueCollection != null)
1223 scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
1227 Trace.Write ("aspx.page", "Begin LoadViewState");
1228 LoadPageViewState ();
1229 Trace.Write ("aspx.page", "End LoadViewState");
1230 Trace.Write ("aspx.page", "Begin ProcessPostData");
1231 ProcessPostData (_requestValueCollection, false);
1232 Trace.Write ("aspx.page", "End ProcessPostData");
1236 OnPreLoad (EventArgs.Empty);
1237 _lifeCycle = PageLifeCycle.Load;
1242 if (IsPostBack || IsCallback) {
1243 _lifeCycle = PageLifeCycle.ControlEvents;
1247 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1248 ProcessPostData (secondPostData, true);
1249 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1250 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1251 RaiseChangedEvents ();
1252 Trace.Write ("aspx.page", "End Raise ChangedEvents");
1253 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1254 RaisePostBackEvents ();
1255 Trace.Write ("aspx.page", "End Raise PostBackEvent");
1259 _lifeCycle = PageLifeCycle.LoadComplete;
1260 OnLoadComplete (EventArgs.Empty);
1262 if (IsCrossPagePostBack)
1266 string result = ProcessCallbackData ();
1267 HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
1268 callbackOutput.Write (result);
1269 callbackOutput.Flush ();
1273 _lifeCycle = PageLifeCycle.PreRender;
1276 Trace.Write ("aspx.page", "Begin PreRender");
1277 PreRenderRecursiveInternal ();
1278 Trace.Write ("aspx.page", "End PreRender");
1281 _lifeCycle = PageLifeCycle.PreRenderComplete;
1282 OnPreRenderComplete (EventArgs.Empty);
1285 Trace.Write ("aspx.page", "Begin SaveViewState");
1286 SavePageViewState ();
1287 Trace.Write ("aspx.page", "End SaveViewState");
1290 _lifeCycle = PageLifeCycle.SaveStateComplete;
1291 OnSaveStateComplete (EventArgs.Empty);
1295 if (SaveViewStateForNextPortletRender())
1300 _lifeCycle = PageLifeCycle.Render;
1304 Trace.Write ("aspx.page", "Begin Render");
1305 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1306 RenderControl (output);
1307 Trace.Write ("aspx.page", "End Render");
1310 private void RenderTrace ()
1312 TraceManager traceManager = HttpRuntime.TraceManager;
1314 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1319 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
1322 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1323 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1324 Trace.Render (output);
1329 bool CheckForValidationSupport (Control targetControl)
1331 if (targetControl == null)
1333 Type type = targetControl.GetType ();
1334 object[] attributes = type.GetCustomAttributes (false);
1335 foreach (object attr in attributes)
1336 if (attr is SupportsEventValidationAttribute)
1342 void RaisePostBackEvents ()
1345 Control targetControl;
1347 if (requiresRaiseEvent != null) {
1348 RaisePostBackEvent (requiresRaiseEvent, null);
1352 NameValueCollection postdata = _requestValueCollection;
1353 if (postdata == null)
1356 string eventTarget = postdata [postEventSourceID];
1357 if (eventTarget == null || eventTarget.Length == 0) {
1363 targetControl = FindControl (eventTarget);
1364 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1366 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
1372 string eventArgument = postdata [postEventArgumentID];
1373 RaisePostBackEvent (target, eventArgument);
1376 internal void RaiseChangedEvents ()
1378 if (requiresPostDataChanged == null)
1381 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1382 ipdh.RaisePostDataChangedEvent ();
1384 requiresPostDataChanged = null;
1387 [EditorBrowsable (EditorBrowsableState.Advanced)]
1388 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1391 Control targetControl = sourceControl as Control;
1392 if (targetControl != null && CheckForValidationSupport (targetControl))
1393 scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
1395 sourceControl.RaisePostBackEvent (eventArgument);
1401 [EditorBrowsable (EditorBrowsableState.Advanced)]
1402 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1404 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1410 [EditorBrowsable (EditorBrowsableState.Advanced)]
1411 public virtual void RegisterClientScriptBlock (string key, string script)
1413 scriptManager.RegisterClientScriptBlock (key, script);
1419 [EditorBrowsable (EditorBrowsableState.Advanced)]
1420 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1422 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1425 [MonoTODO("Not implemented, Used in HtmlForm")]
1426 internal void RegisterClientScriptFile (string a, string b, string c)
1428 throw new NotImplementedException ();
1434 [EditorBrowsable (EditorBrowsableState.Advanced)]
1435 public void RegisterOnSubmitStatement (string key, string script)
1437 scriptManager.RegisterOnSubmitStatement (key, script);
1440 internal string GetSubmitStatements ()
1442 return scriptManager.WriteSubmitStatements ();
1445 [EditorBrowsable (EditorBrowsableState.Advanced)]
1446 public void RegisterRequiresPostBack (Control control)
1448 if (_requiresPostBack == null)
1449 _requiresPostBack = new ArrayList ();
1451 if (_requiresPostBack.Contains (control.UniqueID))
1454 _requiresPostBack.Add (control.UniqueID);
1457 [EditorBrowsable (EditorBrowsableState.Advanced)]
1458 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1460 requiresRaiseEvent = control;
1466 [EditorBrowsable (EditorBrowsableState.Advanced)]
1467 public virtual void RegisterStartupScript (string key, string script)
1469 scriptManager.RegisterStartupScript (key, script);
1472 [EditorBrowsable (EditorBrowsableState.Advanced)]
1473 public void RegisterViewStateHandler ()
1475 handleViewState = true;
1478 [EditorBrowsable (EditorBrowsableState.Advanced)]
1479 protected virtual void SavePageStateToPersistenceMedium (object viewState)
1481 PageStatePersister persister = this.PageStatePersister;
1482 if (persister == null)
1484 Pair pair = viewState as Pair;
1486 persister.ViewState = pair.First;
1487 persister.ControlState = pair.Second;
1489 persister.ViewState = viewState;
1493 internal string RawViewState {
1495 NameValueCollection postdata = _requestValueCollection;
1497 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1500 if (view_state == "")
1504 set { _savedViewState = value; }
1512 PageStatePersister PageStatePersister {
1514 if (page_state_persister == null)
1515 page_state_persister = new HiddenFieldPageStatePersister (this);
1516 return page_state_persister;
1520 [EditorBrowsable (EditorBrowsableState.Advanced)]
1521 protected virtual object LoadPageStateFromPersistenceMedium ()
1523 PageStatePersister persister = this.PageStatePersister;
1524 if (persister == null)
1527 return new Pair (persister.ViewState, persister.ControlState);
1530 internal void LoadPageViewState()
1532 Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
1533 if (sState != null) {
1536 LoadPageControlState (sState.Second);
1538 Pair vsr = sState.First as Pair;
1540 LoadViewStateRecursive (vsr.First);
1541 _requiresPostBackCopy = vsr.Second as ArrayList;
1547 internal void SavePageViewState ()
1549 if (!handleViewState)
1553 object controlState = SavePageControlState ();
1556 object viewState = SaveViewStateRecursive ();
1557 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1560 if (viewState != null || reqPostback != null)
1561 vsr = new Pair (viewState, reqPostback);
1562 Pair pair = new Pair ();
1566 pair.Second = controlState;
1570 if (pair.First == null && pair.Second == null)
1571 SavePageStateToPersistenceMedium (null);
1573 SavePageStateToPersistenceMedium (pair);
1577 public virtual void Validate ()
1579 is_validated = true;
1580 ValidateCollection (_validators);
1584 internal bool AreValidatorsUplevel () {
1585 return AreValidatorsUplevel (String.Empty);
1588 internal bool AreValidatorsUplevel (string valGroup)
1590 internal virtual bool AreValidatorsUplevel ()
1593 bool uplevel = false;
1595 foreach (IValidator v in Validators) {
1596 BaseValidator bv = v as BaseValidator;
1597 if (bv == null) continue;
1600 if (valGroup != bv.ValidationGroup)
1603 if (bv.GetRenderUplevel()) {
1612 bool ValidateCollection (ValidatorCollection validators)
1615 if (!_eventValidation)
1619 if (validators == null || validators.Count == 0)
1622 bool all_valid = true;
1623 foreach (IValidator v in validators){
1625 if (v.IsValid == false)
1632 [EditorBrowsable (EditorBrowsableState.Advanced)]
1633 public virtual void VerifyRenderingInServerForm (Control control)
1635 if (_context == null)
1642 throw new HttpException ("Control '" +
1645 control.GetType ().Name +
1646 "' must be placed inside a form tag with runat=server.");
1649 protected override void FrameworkInitialize ()
1651 base.FrameworkInitialize ();
1653 InitializeStyleSheet ();
1664 ClientScriptManager ClientScript {
1665 get { return scriptManager; }
1670 static readonly object InitCompleteEvent = new object ();
1671 static readonly object LoadCompleteEvent = new object ();
1672 static readonly object PreInitEvent = new object ();
1673 static readonly object PreLoadEvent = new object ();
1674 static readonly object PreRenderCompleteEvent = new object ();
1675 static readonly object SaveStateCompleteEvent = new object ();
1677 const int initcomplete_mask = 1;
1678 const int loadcomplete_mask = 1 << 1;
1679 const int preinit_mask = 1 << 2;
1680 const int preload_mask = 1 << 3;
1681 const int prerendercomplete_mask = 1 << 4;
1682 const int savestatecomplete_mask = 1 << 5;
1684 [EditorBrowsable (EditorBrowsableState.Advanced)]
1685 public event EventHandler InitComplete {
1687 event_mask |= initcomplete_mask;
1688 Events.AddHandler (InitCompleteEvent, value);
1690 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1693 [EditorBrowsable (EditorBrowsableState.Advanced)]
1694 public event EventHandler LoadComplete {
1696 event_mask |= loadcomplete_mask;
1697 Events.AddHandler (LoadCompleteEvent, value);
1699 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1702 public event EventHandler PreInit {
1704 event_mask |= preinit_mask;
1705 Events.AddHandler (PreInitEvent, value);
1707 remove { Events.RemoveHandler (PreInitEvent, value); }
1710 [EditorBrowsable (EditorBrowsableState.Advanced)]
1711 public event EventHandler PreLoad {
1713 event_mask |= preload_mask;
1714 Events.AddHandler (PreLoadEvent, value);
1716 remove { Events.RemoveHandler (PreLoadEvent, value); }
1719 [EditorBrowsable (EditorBrowsableState.Advanced)]
1720 public event EventHandler PreRenderComplete {
1722 event_mask |= prerendercomplete_mask;
1723 Events.AddHandler (PreRenderCompleteEvent, value);
1725 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
1728 [EditorBrowsable (EditorBrowsableState.Advanced)]
1729 public event EventHandler SaveStateComplete {
1731 event_mask |= savestatecomplete_mask;
1732 Events.AddHandler (SaveStateCompleteEvent, value);
1734 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
1737 protected virtual void OnInitComplete (EventArgs e)
1739 if ((event_mask & initcomplete_mask) != 0) {
1740 EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
1741 if (eh != null) eh (this, e);
1745 protected virtual void OnLoadComplete (EventArgs e)
1747 if ((event_mask & loadcomplete_mask) != 0) {
1748 EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
1749 if (eh != null) eh (this, e);
1753 protected virtual void OnPreInit (EventArgs e)
1755 if ((event_mask & preinit_mask) != 0) {
1756 EventHandler eh = (EventHandler) (Events [PreInitEvent]);
1757 if (eh != null) eh (this, e);
1761 protected virtual void OnPreLoad (EventArgs e)
1763 if ((event_mask & preload_mask) != 0) {
1764 EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
1765 if (eh != null) eh (this, e);
1769 protected virtual void OnPreRenderComplete (EventArgs e)
1771 if ((event_mask & prerendercomplete_mask) != 0) {
1772 EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
1773 if (eh != null) eh (this, e);
1778 if (!Form.DetermineRenderUplevel ())
1781 /* figure out if we have some control we're going to focus */
1782 if (String.IsNullOrEmpty (_focusedControlID)) {
1783 _focusedControlID = Form.DefaultFocus;
1784 if (String.IsNullOrEmpty (_focusedControlID))
1785 _focusedControlID = Form.DefaultButton;
1788 if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
1790 RequiresPostBackScript ();
1791 ClientScript.RegisterWebFormClientScript ();
1793 if (!String.IsNullOrEmpty (_focusedControlID)) {
1794 ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
1795 String.Format ("<script type=\"text/javascript\">\n" +
1797 "WebForm_AutoFocus('{0}');// -->\n" +
1798 "</script>\n", _focusedControlID));
1801 if (Form.SubmitDisabledControls) {
1802 ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
1803 "javascript: return WebForm_OnSubmit(" + theForm + ");");
1804 ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
1805 @"<script language=""JavaScript"">
1807 function WebForm_OnSubmit(currForm) {
1808 WebForm_ReEnableControls(currForm);
1816 protected virtual void OnSaveStateComplete (EventArgs e)
1818 if ((event_mask & savestatecomplete_mask) != 0) {
1819 EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
1820 if (eh != null) eh (this, e);
1824 public HtmlForm Form {
1825 get { return _form; }
1828 internal void RegisterForm (HtmlForm form)
1833 [BrowsableAttribute (false)]
1834 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1835 public Page PreviousPage {
1837 if (_doLoadPreviousPage) {
1838 _doLoadPreviousPage = false;
1839 LoadPreviousPageReference ();
1841 return previousPage;
1846 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1847 [BrowsableAttribute (false)]
1848 public bool IsCallback {
1849 get { return isCallback; }
1852 [BrowsableAttribute (false)]
1853 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1854 public bool IsCrossPagePostBack {
1855 get { return isCrossPagePostBack; }
1858 public new virtual char IdSeparator {
1860 //TODO: why override?
1861 return base.IdSeparator;
1865 string ProcessCallbackData ()
1867 string callbackTarget = _requestValueCollection [CallbackSourceID];
1868 if (callbackTarget == null || callbackTarget.Length == 0)
1869 throw new HttpException ("Callback target not provided.");
1871 Control targetControl = FindControl (callbackTarget);
1872 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
1874 throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
1876 string callbackArgument = _requestValueCollection [CallbackArgumentID];
1877 target.RaiseCallbackEvent (callbackArgument);
1879 string eventValidation = ClientScript.GetEventValidationStateFormatted ();
1880 string callBackResult= target.GetCallbackResult ();
1882 return String.Format ("{0}|{1}{2}", eventValidation == null ? 0 : eventValidation.Length, eventValidation, callBackResult);
1885 [BrowsableAttribute (false)]
1886 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1887 public HtmlHead Header {
1888 get { return htmlHeader; }
1891 internal void SetHeader (HtmlHead header)
1893 htmlHeader = header;
1894 if (_title != null) {
1895 htmlHeader.Title = _title;
1900 [MonoTODO("Not Implemented")]
1901 protected bool AsyncMode {
1903 throw new NotImplementedException ();
1906 throw new NotImplementedException ();
1910 [MonoTODO ("Not Implemented")]
1911 public TimeSpan AsyncTimeout {
1913 throw new NotImplementedException ();
1916 throw new NotImplementedException ();
1920 [MonoTODO ("Not Implemented")]
1921 public bool IsAsync {
1923 throw new NotImplementedException ();
1927 [MonoTODO ("Not Implemented")]
1928 protected internal virtual string UniqueFilePathSuffix {
1930 throw new NotImplementedException ();
1934 [MonoTODO ("Not Implemented")]
1935 public int MaxPageStateFieldLength {
1937 throw new NotImplementedException ();
1940 throw new NotImplementedException ();
1944 [MonoTODO ("Not Implemented")]
1945 public ViewStateEncryptionMode ViewStateEncryptionMode {
1947 throw new NotImplementedException ();
1950 throw new NotImplementedException ();
1954 [MonoTODO ("Not Implemented")]
1955 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
1957 throw new NotImplementedException ();
1960 [MonoTODO ("Not Implemented")]
1961 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
1963 throw new NotImplementedException ();
1966 [MonoTODO ("Not Implemented")]
1967 public void ExecuteRegisteredAsyncTasks ()
1969 throw new NotImplementedException ();
1972 [MonoTODO ("Not Implemented")]
1973 public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
1975 throw new NotImplementedException ();
1978 [MonoTODO ("Not Implemented")]
1979 public void RegisterRequiresViewStateEncryption ()
1981 throw new NotImplementedException ();
1984 void ApplyMasterPage ()
1986 if (masterPageFile != null && masterPageFile.Length > 0) {
1987 ArrayList appliedMasterPageFiles = new ArrayList ();
1989 if (Master != null) {
1990 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
1994 Controls.Add (Master);
1999 [DefaultValueAttribute ("")]
2000 public virtual string MasterPageFile {
2001 get { return masterPageFile; }
2003 masterPageFile = value;
2008 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2009 [BrowsableAttribute (false)]
2010 public MasterPage Master {
2012 if (Context == null || String.IsNullOrEmpty (masterPageFile))
2015 if (masterPage == null)
2016 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
2022 public void SetFocus (string clientID)
2024 if (String.IsNullOrEmpty (clientID))
2025 throw new ArgumentNullException ("control");
2027 if (_lifeCycle > PageLifeCycle.PreRender)
2028 throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
2031 throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
2033 _focusedControlID = clientID;
2036 public void SetFocus (Control control)
2038 if (control == null)
2039 throw new ArgumentNullException ("control");
2041 SetFocus (control.ClientID);
2044 [EditorBrowsable (EditorBrowsableState.Advanced)]
2045 public void RegisterRequiresControlState (Control control)
2047 if (control == null)
2048 throw new ArgumentNullException ("control");
2050 if (RequiresControlState (control))
2053 if (requireStateControls == null)
2054 requireStateControls = new ArrayList ();
2055 int n = requireStateControls.Add (control);
2057 if (_savedControlState == null || n >= _savedControlState.Length)
2060 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2061 if (parent.IsChildControlStateCleared)
2064 object state = _savedControlState [n];
2066 control.LoadControlState (state);
2069 public bool RequiresControlState (Control control)
2071 if (requireStateControls == null) return false;
2072 return requireStateControls.Contains (control);
2075 [EditorBrowsable (EditorBrowsableState.Advanced)]
2076 public void UnregisterRequiresControlState (Control control)
2078 if (requireStateControls != null)
2079 requireStateControls.Remove (control);
2082 public ValidatorCollection GetValidators (string validationGroup)
2084 string valgr = validationGroup;
2086 valgr = String.Empty;
2088 if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
2089 ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
2091 col = new ValidatorCollection ();
2092 _validatorsByGroup [valgr] = col;
2097 public virtual void Validate (string validationGroup)
2099 is_validated = true;
2100 if (validationGroup == null)
2101 ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
2102 else if (_validatorsByGroup != null) {
2103 ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
2107 object SavePageControlState ()
2109 if (requireStateControls == null) return null;
2110 object[] state = new object [requireStateControls.Count];
2112 bool allNull = true;
2113 for (int n=0; n<state.Length; n++) {
2114 state [n] = ((Control) requireStateControls [n]).SaveControlState ();
2115 if (state [n] != null) allNull = false;
2117 if (allNull) return null;
2121 void LoadPageControlState (object data)
2123 _savedControlState = (object []) data;
2125 if (requireStateControls == null) return;
2127 int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2128 for (int n=0; n < max; n++) {
2129 Control ctl = (Control) requireStateControls [n];
2130 ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2134 void LoadPreviousPageReference ()
2136 if (_requestValueCollection != null) {
2137 string prevPage = _requestValueCollection [PreviousPageID];
2138 if (prevPage != null) {
2139 previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
2140 previousPage.ProcessCrossPagePostBack (_context);
2146 Hashtable contentTemplates;
2147 [EditorBrowsable (EditorBrowsableState.Never)]
2148 protected internal void AddContentTemplate (string templateName, ITemplate template)
2150 if (contentTemplates == null)
2151 contentTemplates = new Hashtable ();
2152 contentTemplates [templateName] = template;
2155 PageTheme _pageTheme;
2156 internal PageTheme PageTheme {
2157 get { return _pageTheme; }
2160 PageTheme _styleSheetPageTheme;
2161 internal PageTheme StyleSheetPageTheme {
2162 get { return _styleSheetPageTheme; }
2167 internal void PushDataItemContext (object o) {
2168 if (dataItemCtx == null)
2169 dataItemCtx = new Stack ();
2171 dataItemCtx.Push (o);
2174 internal void PopDataItemContext () {
2175 if (dataItemCtx == null)
2176 throw new InvalidOperationException ();
2181 public object GetDataItem() {
2182 if (dataItemCtx == null || dataItemCtx.Count == 0)
2183 throw new InvalidOperationException ("No data item");
2185 return dataItemCtx.Peek ();
2188 protected internal override void OnInit (EventArgs e)
2194 ArrayList themes = new ArrayList();
2196 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2197 themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2198 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2199 themes.AddRange (PageTheme.GetStyleSheets ());
2201 foreach (string lss in themes) {
2202 HtmlLink hl = new HtmlLink ();
2203 hl.Href = ResolveUrl (lss);
2204 hl.Attributes["type"] = "text/css";
2205 hl.Attributes["rel"] = "stylesheet";
2206 Header.Controls.Add (hl);
2213 [MonoTODO ("Not implemented. Only used by .net aspx parser")]
2214 protected object GetWrappedFileDependencies (string [] list)
2219 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2220 protected virtual void InitializeCulture ()
2224 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2225 protected internal void AddWrappedFileDependencies (object virtualFileDependencies)