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;
420 case OutputCacheLocation.Any:
421 cache.SetCacheability (HttpCacheability.Public);
422 cache.SetMaxAge (new TimeSpan (0, 0, duration));
423 cache.SetLastModified (_context.Timestamp);
424 goto case OutputCacheLocation.Server;
425 case OutputCacheLocation.Client:
426 cache.SetCacheability (HttpCacheability.Private);
427 cache.SetMaxAge (new TimeSpan (0, 0, duration));
428 cache.SetLastModified (_context.Timestamp);
430 case OutputCacheLocation.Downstream:
431 cache.SetCacheability (HttpCacheability.Public);
432 cache.SetMaxAge (new TimeSpan (0, 0, duration));
433 cache.SetLastModified (_context.Timestamp);
435 case OutputCacheLocation.Server:
436 if (varyByCustom != null)
437 cache.SetVaryByCustom (varyByCustom);
439 if (varyByParam.Length > 0) {
440 string[] prms = varyByParam.Split (';');
441 foreach (string p in prms)
442 cache.VaryByParams [p.Trim ()] = true;
443 cache.VaryByParams.IgnoreParams = false;
445 cache.VaryByParams.IgnoreParams = true;
448 if (varyByHeader != null) {
449 string[] hdrs = varyByHeader.Split (';');
450 foreach (string h in hdrs)
451 cache.VaryByHeaders [h.Trim ()] = true;
454 case OutputCacheLocation.None:
457 cache.Duration = duration;
458 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
461 [EditorBrowsable (EditorBrowsableState.Advanced)]
462 public bool IsClientScriptBlockRegistered (string key)
464 if (clientScriptBlocks == null)
467 return clientScriptBlocks.ContainsKey (key);
470 [EditorBrowsable (EditorBrowsableState.Advanced)]
471 public bool IsStartupScriptRegistered (string key)
473 if (startupScriptBlocks == null)
476 return startupScriptBlocks.ContainsKey (key);
479 public string MapPath (string virtualPath)
481 return Request.MapPath (virtualPath);
484 private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
486 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
487 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
489 writer.WriteLine ("<script language=\"javascript\">");
490 writer.WriteLine ("<!--");
491 writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
492 writer.WriteLine ("\t\tvar theform = document.getElementById ('{0}');", formUniqueID);
493 writer.WriteLine ("\t\ttheform.{0}.value = eventTarget;", postEventSourceID);
494 writer.WriteLine ("\t\ttheform.{0}.value = eventArgument;", postEventArgumentID);
495 writer.WriteLine ("\t\ttheform.submit();");
496 writer.WriteLine ("\t}");
497 writer.WriteLine ("// -->");
498 writer.WriteLine ("</script>");
501 static void WriteScripts (HtmlTextWriter writer, Hashtable scripts)
506 foreach (string key in scripts.Values)
507 writer.WriteLine (key);
510 void WriteHiddenFields (HtmlTextWriter writer)
512 if (hiddenFields == null)
515 foreach (string key in hiddenFields.Keys) {
516 string value = hiddenFields [key] as string;
517 writer.WriteLine ("\n<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />", key, value);
523 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
526 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
528 renderingForm = true;
530 WriteHiddenFields (writer);
531 if (requiresPostBackScript) {
532 RenderPostBackScript (writer, formUniqueID);
533 postBackScriptRendered = true;
536 if (handleViewState) {
537 writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
538 writer.WriteLine ("value=\"{0}\" />", GetViewStateString ());
541 WriteScripts (writer, clientScriptBlocks);
544 internal string GetViewStateString ()
546 StringWriter sr = new StringWriter ();
547 LosFormatter fmt = new LosFormatter ();
548 fmt.Serialize (sr, _savedViewState);
549 return sr.GetStringBuilder ().ToString ();
552 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
554 if (registeredArrayDeclares != null) {
556 writer.WriteLine("<script language=\"javascript\">");
557 writer.WriteLine("<!--");
558 IDictionaryEnumerator arrayEnum = registeredArrayDeclares.GetEnumerator();
559 while (arrayEnum.MoveNext()) {
560 writer.Write("\tvar ");
561 writer.Write(arrayEnum.Key);
562 writer.Write(" = new Array(");
563 IEnumerator arrayListEnum = ((ArrayList) arrayEnum.Value).GetEnumerator();
565 while (arrayListEnum.MoveNext()) {
570 writer.Write(arrayListEnum.Current);
572 writer.WriteLine(");");
574 writer.WriteLine("// -->");
575 writer.WriteLine("</script>");
579 if (!postBackScriptRendered && requiresPostBackScript)
580 RenderPostBackScript (writer, formUniqueID);
582 WriteHiddenFields (writer);
583 WriteScripts (writer, startupScriptBlocks);
584 renderingForm = false;
585 postBackScriptRendered = false;
588 private void ProcessPostData (NameValueCollection data, bool second)
593 if (_requiresPostBackCopy == null && _requiresPostBack != null)
594 _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
596 Hashtable used = new Hashtable ();
597 foreach (string id in data.AllKeys){
598 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
602 int dot = real_id.IndexOf ('.');
604 real_id = real_id.Substring (0, dot);
606 if (real_id == null || used.ContainsKey (real_id))
609 used.Add (real_id, real_id);
611 Control ctrl = FindControl (real_id);
613 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
614 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
618 RegisterRequiresRaiseEvent (pbeh);
622 if (pbdh.LoadPostData (real_id, data) == true) {
623 if (requiresPostDataChanged == null)
624 requiresPostDataChanged = new ArrayList ();
625 requiresPostDataChanged.Add (pbdh);
626 if (_requiresPostBackCopy != null)
627 _requiresPostBackCopy.Remove (ctrl.UniqueID);
629 } else if (!second) {
630 if (secondPostData == null)
631 secondPostData = new NameValueCollection ();
632 secondPostData.Add (real_id, data [id]);
636 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
637 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
638 foreach (string id in handlers) {
639 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
643 _requiresPostBackCopy.Remove (id);
644 if (pbdh.LoadPostData (id, data)) {
645 if (requiresPostDataChanged == null)
646 requiresPostDataChanged = new ArrayList ();
648 requiresPostDataChanged.Add (pbdh);
654 [EditorBrowsable (EditorBrowsableState.Never)]
655 public void ProcessRequest (HttpContext context)
658 WireupAutomaticEvents ();
659 //-- Control execution lifecycle in the docs
661 // Save culture information because it can be modified in FrameworkInitialize()
662 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
663 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
664 FrameworkInitialize ();
665 context.ErrorPage = _errorPage;
668 InternalProcessRequest ();
671 UnloadRecursive (true);
673 Thread.CurrentThread.CurrentCulture = culture;
674 Thread.CurrentThread.CurrentUICulture = uiculture;
678 void InternalProcessRequest ()
680 Trace.Write ("aspx.page", "Begin Init");
681 InitRecursive (null);
682 Trace.Write ("aspx.page", "End Init");
684 renderingForm = false;
686 Trace.Write ("aspx.page", "Begin LoadViewState");
687 LoadPageViewState ();
688 Trace.Write ("aspx.page", "End LoadViewState");
689 Trace.Write ("aspx.page", "Begin ProcessPostData");
690 ProcessPostData (DeterminePostBackMode (), false);
691 Trace.Write ("aspx.page", "End ProcessPostData");
696 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
697 ProcessPostData (secondPostData, true);
698 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
699 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
700 RaiseChangedEvents ();
701 Trace.Write ("aspx.page", "End Raise ChangedEvents");
702 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
703 RaisePostBackEvents ();
704 Trace.Write ("aspx.page", "End Raise PostBackEvent");
706 Trace.Write ("aspx.page", "Begin PreRender");
707 PreRenderRecursiveInternal ();
708 Trace.Write ("aspx.page", "End PreRender");
710 Trace.Write ("aspx.page", "Begin SaveViewState");
711 SavePageViewState ();
712 Trace.Write ("aspx.page", "End SaveViewState");
715 Trace.Write ("aspx.page", "Begin Render");
716 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
717 RenderControl (output);
718 Trace.Write ("aspx.page", "End Render");
720 RenderTrace (output);
724 private void RenderTrace (HtmlTextWriter output)
726 TraceManager manager = HttpRuntime.TraceManager;
728 if (!Trace.IsEnabled && !manager.Enabled)
733 if (Trace.IsEnabled || manager.PageOutput)
734 Trace.Render (output);
737 internal void RaisePostBackEvents ()
739 if (requiresRaiseEvent != null) {
740 RaisePostBackEvent (requiresRaiseEvent, null);
744 NameValueCollection postdata = DeterminePostBackMode ();
745 if (postdata == null)
748 string eventTarget = postdata [postEventSourceID];
749 if (eventTarget == null || eventTarget.Length == 0)
752 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
756 string eventArgument = postdata [postEventArgumentID];
757 RaisePostBackEvent (target, eventArgument);
760 internal void RaiseChangedEvents ()
762 if (requiresPostDataChanged == null)
765 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
766 ipdh.RaisePostDataChangedEvent ();
768 requiresPostDataChanged = null;
771 [EditorBrowsable (EditorBrowsableState.Advanced)]
772 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
774 sourceControl.RaisePostBackEvent (eventArgument);
777 [EditorBrowsable (EditorBrowsableState.Advanced)]
778 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
780 if (registeredArrayDeclares == null)
781 registeredArrayDeclares = new Hashtable();
783 if (!registeredArrayDeclares.ContainsKey (arrayName))
784 registeredArrayDeclares.Add (arrayName, new ArrayList());
786 ((ArrayList) registeredArrayDeclares[arrayName]).Add(arrayValue);
789 [EditorBrowsable (EditorBrowsableState.Advanced)]
790 public virtual void RegisterClientScriptBlock (string key, string script)
792 if (IsClientScriptBlockRegistered (key))
795 if (clientScriptBlocks == null)
796 clientScriptBlocks = new Hashtable ();
798 clientScriptBlocks.Add (key, script);
801 [EditorBrowsable (EditorBrowsableState.Advanced)]
802 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
804 if (hiddenFields == null)
805 hiddenFields = new Hashtable ();
807 if (!hiddenFields.ContainsKey (hiddenFieldName))
808 hiddenFields.Add (hiddenFieldName, hiddenFieldInitialValue);
810 [MonoTODO("Used in HtmlForm")]
811 internal void RegisterClientScriptFile (string a, string b, string c)
813 throw new NotImplementedException ();
818 [EditorBrowsable (EditorBrowsableState.Advanced)]
819 public void RegisterOnSubmitStatement (string key, string script)
821 if (submitStatements == null)
822 submitStatements = new Hashtable ();
824 if (submitStatements.ContainsKey (key))
827 submitStatements.Add (key, script);
830 [EditorBrowsable (EditorBrowsableState.Advanced)]
831 public void RegisterRequiresPostBack (Control control)
833 if (_requiresPostBack == null)
834 _requiresPostBack = new ArrayList ();
836 _requiresPostBack.Add (control.UniqueID);
839 [EditorBrowsable (EditorBrowsableState.Advanced)]
840 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
842 requiresRaiseEvent = control;
845 [EditorBrowsable (EditorBrowsableState.Advanced)]
846 public virtual void RegisterStartupScript (string key, string script)
848 if (IsStartupScriptRegistered (key))
851 if (startupScriptBlocks == null)
852 startupScriptBlocks = new Hashtable ();
854 startupScriptBlocks.Add (key, script);
857 [EditorBrowsable (EditorBrowsableState.Advanced)]
858 public void RegisterViewStateHandler ()
860 handleViewState = true;
863 [EditorBrowsable (EditorBrowsableState.Advanced)]
864 protected virtual void SavePageStateToPersistenceMedium (object viewState)
866 _savedViewState = viewState;
869 [EditorBrowsable (EditorBrowsableState.Advanced)]
870 protected virtual object LoadPageStateFromPersistenceMedium ()
872 NameValueCollection postdata = DeterminePostBackMode ();
874 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
877 _savedViewState = null;
878 LosFormatter fmt = new LosFormatter ();
881 _savedViewState = fmt.Deserialize (view_state);
882 } catch (Exception e) {
883 throw new HttpException ("Error restoring page viewstate.\n", e);
886 return _savedViewState;
889 internal void LoadPageViewState()
891 object sState = LoadPageStateFromPersistenceMedium ();
892 if (sState != null) {
893 Pair pair = (Pair) sState;
894 LoadViewStateRecursive (pair.First);
895 _requiresPostBack = pair.Second as ArrayList;
899 internal void SavePageViewState ()
901 if (!handleViewState)
904 Pair pair = new Pair ();
905 pair.First = SaveViewStateRecursive ();
906 if (_requiresPostBack != null && _requiresPostBack.Count > 0)
907 pair.Second = _requiresPostBack;
909 if (pair.First == null && pair.Second == null)
912 SavePageStateToPersistenceMedium (pair);
915 public virtual void Validate ()
917 if (_validators == null || _validators.Count == 0){
922 bool all_valid = true;
923 foreach (IValidator v in _validators){
925 if (v.IsValid == false)
933 [EditorBrowsable (EditorBrowsableState.Advanced)]
934 public virtual void VerifyRenderingInServerForm (Control control)
937 throw new HttpException ("Control '" + control.ClientID + " " + control.GetType () +
938 "' must be rendered within a HtmlForm");
944 public string GetWebResourceUrl(Type type, string resourceName)
947 throw new ArgumentNullException ("type");
949 if (resourceName == null || resourceName.Length == 0)
950 throw new ArgumentNullException ("type");
952 return System.Web.Handlers.AssemblyResourceLoader.GetResourceUrl (type, resourceName);
957 internal void PushDataItemContext (object o)
959 if (dataItemCtx == null)
960 dataItemCtx = new Stack ();
962 dataItemCtx.Push (o);
965 internal void PopDataItemContext ()
967 if (dataItemCtx == null)
968 throw new InvalidOperationException ();
973 internal object CurrentDataItem {
975 if (dataItemCtx == null)
976 throw new InvalidOperationException ("No data item");
978 return dataItemCtx.Peek ();
982 protected object Eval (string expression)
984 return DataBinder.Eval (CurrentDataItem, expression);
987 protected object Eval (string expression, string format)
989 return DataBinder.Eval (CurrentDataItem, expression, format);
992 protected object XPath (string xpathexpression)
994 return XPathBinder.Eval (CurrentDataItem, xpathexpression);
997 protected object XPath (string xpathexpression, string format)
999 return XPathBinder.Eval (CurrentDataItem, xpathexpression, format);
1002 protected IEnumerable XPathSelect (string xpathexpression)
1004 return XPathBinder.Select (CurrentDataItem, xpathexpression);