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 // (c) 2003 Novell, Inc. (http://www.novell.com)
14 using System.Collections;
15 using System.Collections.Specialized;
16 using System.ComponentModel;
17 using System.ComponentModel.Design;
18 using System.ComponentModel.Design.Serialization;
19 using System.Globalization;
21 using System.Security.Principal;
23 using System.Threading;
25 using System.Web.Caching;
26 using System.Web.SessionState;
27 using System.Web.Util;
29 namespace System.Web.UI
32 [MonoTODO ("FIXME missing the IRootDesigner Attribute")]
33 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
35 [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
36 [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
37 public class Page : TemplateControl, IHttpHandler
39 private bool _viewState = true;
40 private bool _viewStateMac;
41 private string _errorPage;
42 private bool _isValid;
43 private bool _smartNavigation;
44 private int _transactionMode;
45 private HttpContext _context;
46 private ValidatorCollection _validators;
47 private bool renderingForm;
48 private object _savedViewState;
49 private ArrayList _requiresPostBack;
50 private ArrayList _requiresPostBackCopy;
51 private ArrayList requiresPostDataChanged;
52 private IPostBackEventHandler requiresRaiseEvent;
53 private NameValueCollection secondPostData;
54 private bool requiresPostBackScript;
55 private bool postBackScriptRendered;
56 private Hashtable registeredArrayDeclares;
57 Hashtable clientScriptBlocks;
58 Hashtable startupScriptBlocks;
59 Hashtable hiddenFields;
60 internal Hashtable submitStatements;
62 string viewStateUserKey;
64 [EditorBrowsable (EditorBrowsableState.Never)]
65 protected const string postEventArgumentID = "__EVENTARGUMENT";
66 [EditorBrowsable (EditorBrowsableState.Never)]
67 protected const string postEventSourceID = "__EVENTTARGET";
79 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
81 public HttpApplicationState Application
83 get { return _context.Application; }
86 [EditorBrowsable (EditorBrowsableState.Never)]
87 protected bool AspCompatMode
89 set { throw new NotImplementedException (); }
92 [EditorBrowsable (EditorBrowsableState.Never)]
95 set { Response.BufferOutput = value; }
98 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
102 get { return _context.Cache; }
106 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
107 [Browsable (false), DefaultValue ("")]
108 [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
109 public string ClientTarget
111 get { throw new NotImplementedException (); }
112 set { throw new NotImplementedException (); }
115 [EditorBrowsable (EditorBrowsableState.Never)]
116 protected int CodePage
118 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
121 [EditorBrowsable (EditorBrowsableState.Never)]
122 protected string ContentType
124 set { Response.ContentType = value; }
127 protected override HttpContext Context
129 get { return _context; }
132 [EditorBrowsable (EditorBrowsableState.Never)]
133 protected string Culture
135 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
139 public override bool EnableViewState
141 get { return _viewState; }
142 set { _viewState = value; }
145 [EditorBrowsable (EditorBrowsableState.Never)]
146 protected bool EnableViewStateMac
148 get { return _viewStateMac; }
149 set { _viewStateMac = value; }
152 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
153 [Browsable (false), DefaultValue ("")]
154 [WebSysDescription ("The URL of a page used for error redirection.")]
155 public string ErrorPage
157 get { return _errorPage; }
160 if (_context != null)
161 _context.ErrorPage = value;
165 [EditorBrowsable (EditorBrowsableState.Never)]
166 protected ArrayList FileDependencies
169 if (Response != null)
170 Response.AddFileDependencies (value);
175 public override string ID
177 get { return base.ID; }
178 set { base.ID = value; }
181 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
183 public bool IsPostBack
186 return (0 == String.Compare (Request.HttpMethod, "POST", true));
190 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
191 public bool IsReusable {
192 get { return false; }
195 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
199 get { return _isValid; }
202 [EditorBrowsable (EditorBrowsableState.Never)]
204 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
207 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
209 public HttpRequest Request
211 get { return _context.Request; }
214 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
216 public HttpResponse Response
218 get { return _context.Response; }
221 [EditorBrowsable (EditorBrowsableState.Never)]
222 protected string ResponseEncoding
224 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
227 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
229 public HttpServerUtility Server
232 return Context.Server;
236 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
238 public virtual HttpSessionState Session
241 if (_context.Session == null)
242 throw new HttpException ("Session state can only be used " +
243 "when enableSessionState is set to true, either " +
244 "in a configuration file or in the Page directive.");
246 return _context.Session;
251 public bool SmartNavigation
253 get { return _smartNavigation; }
254 set { _smartNavigation = value; }
257 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
259 public TraceContext Trace
261 get { return Context.Trace; }
264 [EditorBrowsable (EditorBrowsableState.Never)]
265 protected bool TraceEnabled
267 set { Trace.IsEnabled = value; }
270 [EditorBrowsable (EditorBrowsableState.Never)]
271 protected TraceMode TraceModeValue
273 set { Trace.TraceMode = value; }
276 [EditorBrowsable (EditorBrowsableState.Never)]
277 protected int TransactionMode
279 set { _transactionMode = value; }
282 [EditorBrowsable (EditorBrowsableState.Never)]
283 protected string UICulture
285 set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
288 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
290 public IPrincipal User
292 get { return _context.User; }
295 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
297 public ValidatorCollection Validators
300 if (_validators == null)
301 _validators = new ValidatorCollection ();
306 [MonoTODO ("Use this when encrypting/decrypting ViewState")]
308 public string ViewStateUserKey {
309 get { return viewStateUserKey; }
310 set { viewStateUserKey = value; }
314 public override bool Visible
316 get { return base.Visible; }
317 set { base.Visible = value; }
324 [EditorBrowsable (EditorBrowsableState.Never)]
325 protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
329 throw new NotImplementedException ();
332 [EditorBrowsable (EditorBrowsableState.Never)]
333 protected void AspCompatEndProcessRequest (IAsyncResult result)
335 throw new NotImplementedException ();
338 [EditorBrowsable (EditorBrowsableState.Advanced)]
339 protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
341 return new HtmlTextWriter (tw);
344 [EditorBrowsable (EditorBrowsableState.Never)]
345 public void DesignerInitialize ()
347 InitRecursive (null);
350 [EditorBrowsable (EditorBrowsableState.Advanced)]
351 protected virtual NameValueCollection DeterminePostBackMode ()
353 if (_context == null)
356 HttpRequest req = _context.Request;
360 NameValueCollection coll = null;
364 coll = req.QueryString;
367 if (coll == null || coll ["__VIEWSTATE"] == null)
373 [EditorBrowsable (EditorBrowsableState.Advanced)]
374 public string GetPostBackClientEvent (Control control, string argument)
376 return GetPostBackEventReference (control, argument);
379 [EditorBrowsable (EditorBrowsableState.Advanced)]
380 public string GetPostBackClientHyperlink (Control control, string argument)
382 return "javascript:" + GetPostBackEventReference (control, argument);
385 [EditorBrowsable (EditorBrowsableState.Advanced)]
386 public string GetPostBackEventReference (Control control)
388 return GetPostBackEventReference (control, "");
391 [EditorBrowsable (EditorBrowsableState.Advanced)]
392 public string GetPostBackEventReference (Control control, string argument)
394 RequiresPostBackScript ();
395 return String.Format ("__doPostBack('{0}','{1}')", control.UniqueID, argument);
398 internal void RequiresPostBackScript ()
400 requiresPostBackScript = true;
403 [EditorBrowsable (EditorBrowsableState.Never)]
404 public virtual int GetTypeHashCode ()
410 [EditorBrowsable (EditorBrowsableState.Never)]
411 protected virtual void InitOutputCache (int duration,
414 OutputCacheLocation location,
417 HttpCachePolicy cache = _context.Response.Cache;
418 bool set_vary = false;
421 case OutputCacheLocation.Any:
422 cache.SetCacheability (HttpCacheability.Public);
423 cache.SetMaxAge (new TimeSpan (0, 0, duration));
424 cache.SetLastModified (_context.Timestamp);
427 case OutputCacheLocation.Client:
428 cache.SetCacheability (HttpCacheability.Private);
429 cache.SetMaxAge (new TimeSpan (0, 0, duration));
430 cache.SetLastModified (_context.Timestamp);
432 case OutputCacheLocation.Downstream:
433 cache.SetCacheability (HttpCacheability.Public);
434 cache.SetMaxAge (new TimeSpan (0, 0, duration));
435 cache.SetLastModified (_context.Timestamp);
437 case OutputCacheLocation.Server:
438 cache.SetCacheability (HttpCacheability.Server);
441 case OutputCacheLocation.None:
446 if (varyByCustom != null)
447 cache.SetVaryByCustom (varyByCustom);
449 if (varyByParam != null && varyByParam.Length > 0) {
450 string[] prms = varyByParam.Split (';');
451 foreach (string p in prms)
452 cache.VaryByParams [p.Trim ()] = true;
453 cache.VaryByParams.IgnoreParams = false;
455 cache.VaryByParams.IgnoreParams = true;
458 if (varyByHeader != null && varyByHeader.Length > 0) {
459 string[] hdrs = varyByHeader.Split (';');
460 foreach (string h in hdrs)
461 cache.VaryByHeaders [h.Trim ()] = true;
465 cache.Duration = duration;
466 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
469 [EditorBrowsable (EditorBrowsableState.Advanced)]
470 public bool IsClientScriptBlockRegistered (string key)
472 if (clientScriptBlocks == null)
475 return clientScriptBlocks.ContainsKey (key);
478 [EditorBrowsable (EditorBrowsableState.Advanced)]
479 public bool IsStartupScriptRegistered (string key)
481 if (startupScriptBlocks == null)
484 return startupScriptBlocks.ContainsKey (key);
487 public string MapPath (string virtualPath)
489 return Request.MapPath (virtualPath);
492 private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
494 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
495 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
497 writer.WriteLine ("<script language=\"javascript\">");
498 writer.WriteLine ("<!--");
499 writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
500 writer.WriteLine ("\t\tvar theform = document.getElementById ('{0}');", formUniqueID);
501 writer.WriteLine ("\t\ttheform.{0}.value = eventTarget;", postEventSourceID);
502 writer.WriteLine ("\t\ttheform.{0}.value = eventArgument;", postEventArgumentID);
503 writer.WriteLine ("\t\ttheform.submit();");
504 writer.WriteLine ("\t}");
505 writer.WriteLine ("// -->");
506 writer.WriteLine ("</script>");
509 static void WriteScripts (HtmlTextWriter writer, Hashtable scripts)
514 foreach (string key in scripts.Values)
515 writer.WriteLine (key);
518 void WriteHiddenFields (HtmlTextWriter writer)
520 if (hiddenFields == null)
523 foreach (string key in hiddenFields.Keys) {
524 string value = hiddenFields [key] as string;
525 writer.WriteLine ("\n<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />", key, value);
531 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
534 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
536 renderingForm = true;
538 WriteHiddenFields (writer);
539 if (requiresPostBackScript) {
540 RenderPostBackScript (writer, formUniqueID);
541 postBackScriptRendered = true;
544 if (handleViewState) {
545 writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
546 writer.WriteLine ("value=\"{0}\" />", GetViewStateString ());
549 WriteScripts (writer, clientScriptBlocks);
552 internal string GetViewStateString ()
554 StringWriter sr = new StringWriter ();
555 LosFormatter fmt = new LosFormatter ();
556 fmt.Serialize (sr, _savedViewState);
557 return sr.GetStringBuilder ().ToString ();
560 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
562 if (registeredArrayDeclares != null) {
564 writer.WriteLine("<script language=\"javascript\">");
565 writer.WriteLine("<!--");
566 IDictionaryEnumerator arrayEnum = registeredArrayDeclares.GetEnumerator();
567 while (arrayEnum.MoveNext()) {
568 writer.Write("\tvar ");
569 writer.Write(arrayEnum.Key);
570 writer.Write(" = new Array(");
571 IEnumerator arrayListEnum = ((ArrayList) arrayEnum.Value).GetEnumerator();
573 while (arrayListEnum.MoveNext()) {
578 writer.Write(arrayListEnum.Current);
580 writer.WriteLine(");");
582 writer.WriteLine("// -->");
583 writer.WriteLine("</script>");
587 if (!postBackScriptRendered && requiresPostBackScript)
588 RenderPostBackScript (writer, formUniqueID);
590 WriteHiddenFields (writer);
591 WriteScripts (writer, startupScriptBlocks);
592 renderingForm = false;
593 postBackScriptRendered = false;
596 private void ProcessPostData (NameValueCollection data, bool second)
601 if (_requiresPostBackCopy == null && _requiresPostBack != null)
602 _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
604 Hashtable used = new Hashtable ();
605 foreach (string id in data.AllKeys){
606 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
610 int dot = real_id.IndexOf ('.');
612 real_id = real_id.Substring (0, dot);
614 if (real_id == null || used.ContainsKey (real_id))
617 used.Add (real_id, real_id);
619 Control ctrl = FindControl (real_id);
621 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
622 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
626 RegisterRequiresRaiseEvent (pbeh);
630 if (pbdh.LoadPostData (real_id, data) == true) {
631 if (requiresPostDataChanged == null)
632 requiresPostDataChanged = new ArrayList ();
633 requiresPostDataChanged.Add (pbdh);
634 if (_requiresPostBackCopy != null)
635 _requiresPostBackCopy.Remove (ctrl.UniqueID);
637 } else if (!second) {
638 if (secondPostData == null)
639 secondPostData = new NameValueCollection ();
640 secondPostData.Add (real_id, data [id]);
644 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
645 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
646 foreach (string id in handlers) {
647 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
651 _requiresPostBackCopy.Remove (id);
652 if (pbdh.LoadPostData (id, data)) {
653 if (requiresPostDataChanged == null)
654 requiresPostDataChanged = new ArrayList ();
656 requiresPostDataChanged.Add (pbdh);
662 [EditorBrowsable (EditorBrowsableState.Never)]
663 public void ProcessRequest (HttpContext context)
666 WireupAutomaticEvents ();
667 //-- Control execution lifecycle in the docs
669 // Save culture information because it can be modified in FrameworkInitialize()
670 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
671 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
672 FrameworkInitialize ();
673 context.ErrorPage = _errorPage;
676 InternalProcessRequest ();
679 UnloadRecursive (true);
681 Thread.CurrentThread.CurrentCulture = culture;
682 Thread.CurrentThread.CurrentUICulture = uiculture;
686 void InternalProcessRequest ()
688 Trace.Write ("aspx.page", "Begin Init");
689 InitRecursive (null);
690 Trace.Write ("aspx.page", "End Init");
692 renderingForm = false;
694 Trace.Write ("aspx.page", "Begin LoadViewState");
695 LoadPageViewState ();
696 Trace.Write ("aspx.page", "End LoadViewState");
697 Trace.Write ("aspx.page", "Begin ProcessPostData");
698 ProcessPostData (DeterminePostBackMode (), false);
699 Trace.Write ("aspx.page", "End ProcessPostData");
704 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
705 ProcessPostData (secondPostData, true);
706 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
707 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
708 RaiseChangedEvents ();
709 Trace.Write ("aspx.page", "End Raise ChangedEvents");
710 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
711 RaisePostBackEvents ();
712 Trace.Write ("aspx.page", "End Raise PostBackEvent");
714 Trace.Write ("aspx.page", "Begin PreRender");
715 PreRenderRecursiveInternal ();
716 Trace.Write ("aspx.page", "End PreRender");
718 Trace.Write ("aspx.page", "Begin SaveViewState");
719 SavePageViewState ();
720 Trace.Write ("aspx.page", "End SaveViewState");
723 Trace.Write ("aspx.page", "Begin Render");
724 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
725 RenderControl (output);
726 Trace.Write ("aspx.page", "End Render");
728 RenderTrace (output);
732 private void RenderTrace (HtmlTextWriter output)
734 TraceManager manager = HttpRuntime.TraceManager;
736 if (!Trace.IsEnabled && !manager.Enabled)
741 if (Trace.IsEnabled || manager.PageOutput)
742 Trace.Render (output);
745 internal void RaisePostBackEvents ()
747 if (requiresRaiseEvent != null) {
748 RaisePostBackEvent (requiresRaiseEvent, null);
752 NameValueCollection postdata = DeterminePostBackMode ();
753 if (postdata == null)
756 string eventTarget = postdata [postEventSourceID];
757 if (eventTarget == null || eventTarget.Length == 0) {
762 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
766 string eventArgument = postdata [postEventArgumentID];
767 RaisePostBackEvent (target, eventArgument);
770 internal void RaiseChangedEvents ()
772 if (requiresPostDataChanged == null)
775 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
776 ipdh.RaisePostDataChangedEvent ();
778 requiresPostDataChanged = null;
781 [EditorBrowsable (EditorBrowsableState.Advanced)]
782 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
784 sourceControl.RaisePostBackEvent (eventArgument);
787 [EditorBrowsable (EditorBrowsableState.Advanced)]
788 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
790 if (registeredArrayDeclares == null)
791 registeredArrayDeclares = new Hashtable();
793 if (!registeredArrayDeclares.ContainsKey (arrayName))
794 registeredArrayDeclares.Add (arrayName, new ArrayList());
796 ((ArrayList) registeredArrayDeclares[arrayName]).Add(arrayValue);
799 [EditorBrowsable (EditorBrowsableState.Advanced)]
800 public virtual void RegisterClientScriptBlock (string key, string script)
802 if (IsClientScriptBlockRegistered (key))
805 if (clientScriptBlocks == null)
806 clientScriptBlocks = new Hashtable ();
808 clientScriptBlocks.Add (key, script);
811 [EditorBrowsable (EditorBrowsableState.Advanced)]
812 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
814 if (hiddenFields == null)
815 hiddenFields = new Hashtable ();
817 if (!hiddenFields.ContainsKey (hiddenFieldName))
818 hiddenFields.Add (hiddenFieldName, hiddenFieldInitialValue);
820 [MonoTODO("Used in HtmlForm")]
821 internal void RegisterClientScriptFile (string a, string b, string c)
823 throw new NotImplementedException ();
828 [EditorBrowsable (EditorBrowsableState.Advanced)]
829 public void RegisterOnSubmitStatement (string key, string script)
831 if (submitStatements == null)
832 submitStatements = new Hashtable ();
834 if (submitStatements.ContainsKey (key))
837 submitStatements.Add (key, script);
840 [EditorBrowsable (EditorBrowsableState.Advanced)]
841 public void RegisterRequiresPostBack (Control control)
843 if (_requiresPostBack == null)
844 _requiresPostBack = new ArrayList ();
846 _requiresPostBack.Add (control.UniqueID);
849 [EditorBrowsable (EditorBrowsableState.Advanced)]
850 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
852 requiresRaiseEvent = control;
855 [EditorBrowsable (EditorBrowsableState.Advanced)]
856 public virtual void RegisterStartupScript (string key, string script)
858 if (IsStartupScriptRegistered (key))
861 if (startupScriptBlocks == null)
862 startupScriptBlocks = new Hashtable ();
864 startupScriptBlocks.Add (key, script);
867 [EditorBrowsable (EditorBrowsableState.Advanced)]
868 public void RegisterViewStateHandler ()
870 handleViewState = true;
873 [EditorBrowsable (EditorBrowsableState.Advanced)]
874 protected virtual void SavePageStateToPersistenceMedium (object viewState)
876 _savedViewState = viewState;
879 [EditorBrowsable (EditorBrowsableState.Advanced)]
880 protected virtual object LoadPageStateFromPersistenceMedium ()
882 NameValueCollection postdata = DeterminePostBackMode ();
884 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
887 _savedViewState = null;
888 LosFormatter fmt = new LosFormatter ();
891 _savedViewState = fmt.Deserialize (view_state);
892 } catch (Exception e) {
893 throw new HttpException ("Error restoring page viewstate.\n", e);
896 return _savedViewState;
899 internal void LoadPageViewState()
901 object sState = LoadPageStateFromPersistenceMedium ();
902 if (sState != null) {
903 Pair pair = (Pair) sState;
904 LoadViewStateRecursive (pair.First);
905 _requiresPostBack = pair.Second as ArrayList;
909 internal void SavePageViewState ()
911 if (!handleViewState)
914 Pair pair = new Pair ();
915 pair.First = SaveViewStateRecursive ();
916 if (_requiresPostBack != null && _requiresPostBack.Count > 0)
917 pair.Second = _requiresPostBack;
919 if (pair.First == null && pair.Second == null)
922 SavePageStateToPersistenceMedium (pair);
925 public virtual void Validate ()
927 if (_validators == null || _validators.Count == 0){
932 bool all_valid = true;
933 foreach (IValidator v in _validators){
935 if (v.IsValid == false)
943 [EditorBrowsable (EditorBrowsableState.Advanced)]
944 public virtual void VerifyRenderingInServerForm (Control control)
947 throw new HttpException ("Control '" + control.ClientID + " " + control.GetType () +
948 "' must be rendered within a HtmlForm");
954 public string GetWebResourceUrl(Type type, string resourceName)
957 throw new ArgumentNullException ("type");
959 if (resourceName == null || resourceName.Length == 0)
960 throw new ArgumentNullException ("type");
962 return System.Web.Handlers.AssemblyResourceLoader.GetResourceUrl (type, resourceName);
967 internal void PushDataItemContext (object o)
969 if (dataItemCtx == null)
970 dataItemCtx = new Stack ();
972 dataItemCtx.Push (o);
975 internal void PopDataItemContext ()
977 if (dataItemCtx == null)
978 throw new InvalidOperationException ();
983 internal object CurrentDataItem {
985 if (dataItemCtx == null)
986 throw new InvalidOperationException ("No data item");
988 return dataItemCtx.Peek ();
992 protected object Eval (string expression)
994 return DataBinder.Eval (CurrentDataItem, expression);
997 protected object Eval (string expression, string format)
999 return DataBinder.Eval (CurrentDataItem, expression, format);
1002 protected object XPath (string xpathexpression)
1004 return XPathBinder.Eval (CurrentDataItem, xpathexpression);
1007 protected object XPath (string xpathexpression, string format)
1009 return XPathBinder.Eval (CurrentDataItem, xpathexpression, format);
1012 protected IEnumerable XPathSelect (string xpathexpression)
1014 return XPathBinder.Select (CurrentDataItem, xpathexpression);