Page.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. //
  2. // System.Web.UI.Page.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua ([email protected])
  7. // Andreas Nahr ([email protected])
  8. //
  9. // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  10. //
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Specialized;
  14. using System.ComponentModel;
  15. using System.ComponentModel.Design;
  16. using System.ComponentModel.Design.Serialization;
  17. using System.IO;
  18. using System.Security.Principal;
  19. using System.Text;
  20. using System.Web;
  21. using System.Web.Caching;
  22. using System.Web.SessionState;
  23. using System.Web.Util;
  24. namespace System.Web.UI
  25. {
  26. // TODO FIXME missing the IRootDesigner Attribute
  27. [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
  28. [ToolboxItem (false)]
  29. [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
  30. [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
  31. public class Page : TemplateControl, IHttpHandler
  32. {
  33. private string _culture;
  34. private bool _viewState = true;
  35. private bool _viewStateMac = false;
  36. private string _errorPage;
  37. private string _ID;
  38. private bool _isValid;
  39. private bool _smartNavigation = false;
  40. private TraceContext _trace;
  41. private bool _traceEnabled;
  42. private TraceMode _traceModeValue;
  43. private int _transactionMode;
  44. private string _UICulture;
  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 = false;
  55. private bool postBackScriptRendered = false;
  56. Hashtable clientScriptBlocks;
  57. Hashtable startupScriptBlocks;
  58. Hashtable hiddenFields;
  59. internal Hashtable submitStatements;
  60. bool handleViewState;
  61. [EditorBrowsable (EditorBrowsableState.Never)]
  62. protected const string postEventArgumentID = "__EVENTARGUMENT";
  63. [EditorBrowsable (EditorBrowsableState.Never)]
  64. protected const string postEventSourceID = "__EVENTTARGET";
  65. #region Constructor
  66. public Page ()
  67. {
  68. Page = this;
  69. }
  70. #endregion
  71. #region Properties
  72. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  73. [Browsable (false)]
  74. public HttpApplicationState Application
  75. {
  76. get { return _context.Application; }
  77. }
  78. [EditorBrowsable (EditorBrowsableState.Never)]
  79. protected bool AspCompatMode
  80. {
  81. set { throw new NotImplementedException (); }
  82. }
  83. [EditorBrowsable (EditorBrowsableState.Never)]
  84. protected bool Buffer
  85. {
  86. set { Response.BufferOutput = value; }
  87. }
  88. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  89. [Browsable (false)]
  90. public Cache Cache
  91. {
  92. get { return _context.Cache; }
  93. }
  94. [MonoTODO]
  95. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  96. [Browsable (false), DefaultValue ("")]
  97. [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
  98. public string ClientTarget
  99. {
  100. get { throw new NotImplementedException (); }
  101. set { throw new NotImplementedException (); }
  102. }
  103. [MonoTODO]
  104. [EditorBrowsable (EditorBrowsableState.Never)]
  105. protected int CodePage
  106. {
  107. set { throw new NotImplementedException (); }
  108. }
  109. [MonoTODO]
  110. [EditorBrowsable (EditorBrowsableState.Never)]
  111. protected string ContentType
  112. {
  113. set { throw new NotImplementedException (); }
  114. }
  115. protected override HttpContext Context
  116. {
  117. get { return _context; }
  118. }
  119. [EditorBrowsable (EditorBrowsableState.Never)]
  120. protected string Culture
  121. {
  122. set { _culture = value; }
  123. }
  124. [Browsable (false)]
  125. public override bool EnableViewState
  126. {
  127. get { return _viewState; }
  128. set { _viewState = value; }
  129. }
  130. [EditorBrowsable (EditorBrowsableState.Never)]
  131. protected bool EnableViewStateMac
  132. {
  133. get { return _viewStateMac; }
  134. set { _viewStateMac = value; }
  135. }
  136. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  137. [Browsable (false), DefaultValue ("")]
  138. [WebSysDescription ("The URL of a page used for error redirection.")]
  139. public string ErrorPage
  140. {
  141. get { return _errorPage; }
  142. set { _errorPage = value; }
  143. }
  144. [EditorBrowsable (EditorBrowsableState.Never)]
  145. protected ArrayList FileDependencies
  146. {
  147. set {
  148. if (Response != null)
  149. Response.AddFileDependencies (value);
  150. }
  151. }
  152. [Browsable (false)]
  153. public override string ID
  154. {
  155. get { return _ID; }
  156. set { _ID = value; }
  157. }
  158. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  159. [Browsable (false)]
  160. public bool IsPostBack
  161. {
  162. get {
  163. return (0 == String.Compare (Request.HttpMethod, "POST", true));
  164. }
  165. }
  166. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  167. public bool IsReusable {
  168. get { return false; }
  169. }
  170. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  171. [Browsable (false)]
  172. public bool IsValid
  173. {
  174. get { return _isValid; }
  175. }
  176. [MonoTODO]
  177. [EditorBrowsable (EditorBrowsableState.Never)]
  178. protected int LCID {
  179. set { throw new NotImplementedException (); }
  180. }
  181. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  182. [Browsable (false)]
  183. public HttpRequest Request
  184. {
  185. get { return _context.Request; }
  186. }
  187. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  188. [Browsable (false)]
  189. public HttpResponse Response
  190. {
  191. get { return _context.Response; }
  192. }
  193. [EditorBrowsable (EditorBrowsableState.Never)]
  194. protected string ResponseEncoding
  195. {
  196. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  197. }
  198. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  199. [Browsable (false)]
  200. public HttpServerUtility Server
  201. {
  202. get {
  203. return Context.Server;
  204. }
  205. }
  206. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  207. [Browsable (false)]
  208. public virtual HttpSessionState Session
  209. {
  210. get { return _context.Session; }
  211. }
  212. [Browsable (false)]
  213. public bool SmartNavigation
  214. {
  215. get { return _smartNavigation; }
  216. set { _smartNavigation = value; }
  217. }
  218. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  219. [Browsable (false)]
  220. public TraceContext Trace
  221. {
  222. get { return _trace; }
  223. }
  224. [EditorBrowsable (EditorBrowsableState.Never)]
  225. protected bool TraceEnabled
  226. {
  227. set { _traceEnabled = value; }
  228. }
  229. [EditorBrowsable (EditorBrowsableState.Never)]
  230. protected TraceMode TraceModeValue
  231. {
  232. set { _traceModeValue = value; }
  233. }
  234. [EditorBrowsable (EditorBrowsableState.Never)]
  235. protected int TransactionMode
  236. {
  237. set { _transactionMode = value; }
  238. }
  239. [EditorBrowsable (EditorBrowsableState.Never)]
  240. protected string UICulture
  241. {
  242. set { _UICulture = value; }
  243. }
  244. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  245. [Browsable (false)]
  246. public IPrincipal User
  247. {
  248. get { return _context.User; }
  249. }
  250. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  251. [Browsable (false)]
  252. public ValidatorCollection Validators
  253. {
  254. get {
  255. if (_validators == null)
  256. _validators = new ValidatorCollection ();
  257. return _validators;
  258. }
  259. }
  260. [Browsable (false)]
  261. public override bool Visible
  262. {
  263. get { return base.Visible; }
  264. set { base.Visible = value; }
  265. }
  266. #endregion
  267. #region Methods
  268. [MonoTODO]
  269. [EditorBrowsable (EditorBrowsableState.Never)]
  270. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  271. AsyncCallback cb,
  272. object extraData)
  273. {
  274. throw new NotImplementedException ();
  275. }
  276. [MonoTODO]
  277. [EditorBrowsable (EditorBrowsableState.Never)]
  278. protected void AspCompatEndProcessRequest (IAsyncResult result)
  279. {
  280. throw new NotImplementedException ();
  281. }
  282. [EditorBrowsable (EditorBrowsableState.Advanced)]
  283. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  284. {
  285. return new HtmlTextWriter (tw);
  286. }
  287. [MonoTODO]
  288. [EditorBrowsable (EditorBrowsableState.Never)]
  289. public void DesignerInitialize ()
  290. {
  291. throw new NotImplementedException ();
  292. }
  293. [EditorBrowsable (EditorBrowsableState.Advanced)]
  294. protected virtual NameValueCollection DeterminePostBackMode ()
  295. {
  296. if (_context == null)
  297. return null;
  298. HttpRequest req = _context.Request;
  299. if (req == null)
  300. return null;
  301. NameValueCollection coll = null;
  302. if (IsPostBack)
  303. coll = req.Form;
  304. else
  305. coll = req.QueryString;
  306. if (coll == null || coll ["__VIEWSTATE"] == null)
  307. return null;
  308. return coll;
  309. }
  310. [EditorBrowsable (EditorBrowsableState.Advanced)]
  311. public string GetPostBackClientEvent (Control control, string argument)
  312. {
  313. return GetPostBackEventReference (control, argument);
  314. }
  315. [EditorBrowsable (EditorBrowsableState.Advanced)]
  316. public string GetPostBackClientHyperlink (Control control, string argument)
  317. {
  318. return "javascript:" + GetPostBackEventReference (control, argument);
  319. }
  320. [EditorBrowsable (EditorBrowsableState.Advanced)]
  321. public string GetPostBackEventReference (Control control)
  322. {
  323. return GetPostBackEventReference (control, "");
  324. }
  325. [EditorBrowsable (EditorBrowsableState.Advanced)]
  326. public string GetPostBackEventReference (Control control, string argument)
  327. {
  328. RequiresPostBackScript ();
  329. return String.Format ("__doPostBack ('{0}', '{1}')", control.UniqueID, argument);
  330. }
  331. internal void RequiresPostBackScript ()
  332. {
  333. requiresPostBackScript = true;
  334. }
  335. [EditorBrowsable (EditorBrowsableState.Never)]
  336. public virtual int GetTypeHashCode ()
  337. {
  338. return 0;
  339. }
  340. [MonoTODO]
  341. [EditorBrowsable (EditorBrowsableState.Never)]
  342. protected virtual void InitOutputCache (int duration,
  343. string varyByHeader,
  344. string varyByCustom,
  345. OutputCacheLocation location,
  346. string varyByParam)
  347. {
  348. throw new NotImplementedException ();
  349. }
  350. [EditorBrowsable (EditorBrowsableState.Advanced)]
  351. public bool IsClientScriptBlockRegistered (string key)
  352. {
  353. if (clientScriptBlocks == null)
  354. return false;
  355. return clientScriptBlocks.ContainsKey (key);
  356. }
  357. [EditorBrowsable (EditorBrowsableState.Advanced)]
  358. public bool IsStartupScriptRegistered (string key)
  359. {
  360. if (startupScriptBlocks == null)
  361. return false;
  362. return startupScriptBlocks.ContainsKey (key);
  363. }
  364. public string MapPath (string virtualPath)
  365. {
  366. return Request.MapPath (virtualPath);
  367. }
  368. private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  369. {
  370. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
  371. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
  372. writer.WriteLine ();
  373. writer.WriteLine ("<script language=\"javascript\">");
  374. writer.WriteLine ("<!--");
  375. writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
  376. writer.WriteLine ("\t\tvar theform = document.{0};", formUniqueID);
  377. writer.WriteLine ("\t\ttheform.{0}.value = eventTarget;", postEventSourceID);
  378. writer.WriteLine ("\t\ttheform.{0}.value = eventArgument;", postEventArgumentID);
  379. writer.WriteLine ("\t\ttheform.submit();");
  380. writer.WriteLine ("\t}");
  381. writer.WriteLine ("// -->");
  382. writer.WriteLine ("</script>");
  383. }
  384. static void WriteScripts (HtmlTextWriter writer, Hashtable scripts)
  385. {
  386. if (scripts == null)
  387. return;
  388. foreach (string key in scripts.Values)
  389. writer.WriteLine (key);
  390. }
  391. void WriteHiddenFields (HtmlTextWriter writer)
  392. {
  393. if (hiddenFields == null)
  394. return;
  395. foreach (string key in hiddenFields.Keys) {
  396. string value = hiddenFields [key] as string;
  397. writer.WriteLine ("\n<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />", key, value);
  398. }
  399. hiddenFields = null;
  400. }
  401. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  402. {
  403. if (renderingForm)
  404. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  405. renderingForm = true;
  406. writer.WriteLine ();
  407. WriteHiddenFields (writer);
  408. if (requiresPostBackScript) {
  409. RenderPostBackScript (writer, formUniqueID);
  410. postBackScriptRendered = true;
  411. }
  412. if (handleViewState) {
  413. writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
  414. writer.WriteLine ("value=\"{0}\" />", GetViewStateString ());
  415. }
  416. WriteScripts (writer, clientScriptBlocks);
  417. }
  418. internal string GetViewStateString ()
  419. {
  420. StringWriter sr = new StringWriter ();
  421. LosFormatter fmt = new LosFormatter ();
  422. fmt.Serialize (sr, _savedViewState);
  423. return sr.GetStringBuilder ().ToString ();
  424. }
  425. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  426. {
  427. if (!postBackScriptRendered && requiresPostBackScript)
  428. RenderPostBackScript (writer, formUniqueID);
  429. WriteHiddenFields (writer);
  430. WriteScripts (writer, startupScriptBlocks);
  431. renderingForm = false;
  432. postBackScriptRendered = false;
  433. }
  434. private void ProcessPostData (NameValueCollection data, bool second)
  435. {
  436. if (data == null)
  437. return;
  438. if (_requiresPostBackCopy == null && _requiresPostBack != null)
  439. _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
  440. Hashtable used = new Hashtable ();
  441. foreach (string id in data.AllKeys){
  442. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
  443. continue;
  444. string real_id = id;
  445. int dot = real_id.IndexOf ('.');
  446. if (dot >= 1)
  447. real_id = real_id.Substring (0, dot);
  448. if (real_id == null || used.ContainsKey (real_id))
  449. continue;
  450. used.Add (real_id, real_id);
  451. Control ctrl = FindControl (real_id);
  452. if (ctrl != null){
  453. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  454. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  455. if (pbdh == null) {
  456. if (pbeh != null)
  457. RegisterRequiresRaiseEvent (pbeh);
  458. continue;
  459. }
  460. if (pbdh.LoadPostData (real_id, data) == true) {
  461. if (requiresPostDataChanged == null)
  462. requiresPostDataChanged = new ArrayList ();
  463. requiresPostDataChanged.Add (pbdh);
  464. if (_requiresPostBackCopy != null)
  465. _requiresPostBackCopy.Remove (ctrl.UniqueID);
  466. }
  467. } else if (!second) {
  468. if (secondPostData == null)
  469. secondPostData = new NameValueCollection ();
  470. secondPostData.Add (real_id, data [id]);
  471. }
  472. }
  473. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  474. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  475. foreach (string id in handlers) {
  476. IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
  477. if (pbdh == null)
  478. continue;
  479. _requiresPostBackCopy.Remove (id);
  480. if (pbdh.LoadPostData (id, data)) {
  481. if (requiresPostDataChanged == null)
  482. requiresPostDataChanged = new ArrayList ();
  483. requiresPostDataChanged.Add (pbdh);
  484. }
  485. }
  486. }
  487. }
  488. [EditorBrowsable (EditorBrowsableState.Never)]
  489. public void ProcessRequest (HttpContext context)
  490. {
  491. _context = context;
  492. WebTrace.PushContext ("Page.ProcessRequest ()");
  493. WebTrace.WriteLine ("Entering");
  494. WireupAutomaticEvents ();
  495. WebTrace.WriteLine ("Finished hookup");
  496. //-- Control execution lifecycle in the docs
  497. WebTrace.WriteLine ("FrameworkInitialize");
  498. FrameworkInitialize ();
  499. WebTrace.WriteLine ("InitRecursive");
  500. InitRecursive (null);
  501. renderingForm = false;
  502. if (IsPostBack) {
  503. LoadPageViewState ();
  504. ProcessPostData (DeterminePostBackMode (), false);
  505. }
  506. WebTrace.WriteLine ("LoadRecursive");
  507. LoadRecursive ();
  508. if (IsPostBack) {
  509. ProcessPostData (secondPostData, true);
  510. RaiseChangedEvents ();
  511. RaisePostBackEvents ();
  512. }
  513. WebTrace.WriteLine ("PreRenderRecursiveInternal");
  514. PreRenderRecursiveInternal ();
  515. WebTrace.WriteLine ("SavePageViewState");
  516. SavePageViewState ();
  517. //--
  518. HtmlTextWriter output = new HtmlTextWriter (context.Response.Output);
  519. WebTrace.WriteLine ("RenderControl");
  520. RenderControl (output);
  521. _context = null;
  522. WebTrace.WriteLine ("UnloadRecursive");
  523. UnloadRecursive (true);
  524. WebTrace.WriteLine ("End");
  525. WebTrace.PopContext ();
  526. }
  527. internal void RaisePostBackEvents ()
  528. {
  529. if (requiresRaiseEvent != null) {
  530. RaisePostBackEvent (requiresRaiseEvent, null);
  531. return;
  532. }
  533. NameValueCollection postdata = DeterminePostBackMode ();
  534. if (postdata == null)
  535. return;
  536. string eventTarget = postdata [postEventSourceID];
  537. if (eventTarget == null || eventTarget.Length == 0)
  538. return;
  539. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  540. if (target == null)
  541. return;
  542. string eventArgument = postdata [postEventArgumentID];
  543. RaisePostBackEvent (target, eventArgument);
  544. }
  545. internal void RaiseChangedEvents ()
  546. {
  547. if (requiresPostDataChanged == null)
  548. return;
  549. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  550. ipdh.RaisePostDataChangedEvent ();
  551. requiresPostDataChanged = null;
  552. }
  553. [EditorBrowsable (EditorBrowsableState.Advanced)]
  554. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  555. {
  556. sourceControl.RaisePostBackEvent (eventArgument);
  557. }
  558. [MonoTODO]
  559. [EditorBrowsable (EditorBrowsableState.Advanced)]
  560. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  561. {
  562. throw new NotImplementedException ();
  563. }
  564. [EditorBrowsable (EditorBrowsableState.Advanced)]
  565. public virtual void RegisterClientScriptBlock (string key, string script)
  566. {
  567. if (IsClientScriptBlockRegistered (key))
  568. return;
  569. if (clientScriptBlocks == null)
  570. clientScriptBlocks = new Hashtable ();
  571. clientScriptBlocks.Add (key, script);
  572. }
  573. [EditorBrowsable (EditorBrowsableState.Advanced)]
  574. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  575. {
  576. if (hiddenFields == null)
  577. hiddenFields = new Hashtable ();
  578. if (!hiddenFields.ContainsKey (hiddenFieldName))
  579. hiddenFields.Add (hiddenFieldName, hiddenFieldInitialValue);
  580. }
  581. [MonoTODO]
  582. public void RegisterClientScriptFile (string a, string b, string c)
  583. {
  584. throw new NotImplementedException ();
  585. }
  586. [MonoTODO]
  587. [EditorBrowsable (EditorBrowsableState.Advanced)]
  588. public void RegisterOnSubmitStatement (string key, string script)
  589. {
  590. if (submitStatements == null)
  591. submitStatements = new Hashtable ();
  592. if (submitStatements.ContainsKey (key))
  593. return;
  594. submitStatements.Add (key, script);
  595. }
  596. [EditorBrowsable (EditorBrowsableState.Advanced)]
  597. public void RegisterRequiresPostBack (Control control)
  598. {
  599. if (_requiresPostBack == null)
  600. _requiresPostBack = new ArrayList ();
  601. _requiresPostBack.Add (control.UniqueID);
  602. }
  603. [EditorBrowsable (EditorBrowsableState.Advanced)]
  604. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  605. {
  606. requiresRaiseEvent = control;
  607. }
  608. [EditorBrowsable (EditorBrowsableState.Advanced)]
  609. public virtual void RegisterStartupScript (string key, string script)
  610. {
  611. if (IsStartupScriptRegistered (key))
  612. return;
  613. if (startupScriptBlocks == null)
  614. startupScriptBlocks = new Hashtable ();
  615. startupScriptBlocks.Add (key, script);
  616. }
  617. [EditorBrowsable (EditorBrowsableState.Advanced)]
  618. public void RegisterViewStateHandler ()
  619. {
  620. handleViewState = true;
  621. }
  622. [EditorBrowsable (EditorBrowsableState.Advanced)]
  623. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  624. {
  625. _savedViewState = viewState;
  626. }
  627. [EditorBrowsable (EditorBrowsableState.Advanced)]
  628. protected virtual object LoadPageStateFromPersistenceMedium ()
  629. {
  630. NameValueCollection postdata = DeterminePostBackMode ();
  631. string view_state;
  632. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  633. return null;
  634. _savedViewState = null;
  635. LosFormatter fmt = new LosFormatter ();
  636. try {
  637. _savedViewState = fmt.Deserialize (view_state);
  638. } catch (Exception e) {
  639. throw new HttpException ("Error restoring page viewstate.\n", e);
  640. }
  641. return _savedViewState;
  642. }
  643. internal void LoadPageViewState()
  644. {
  645. WebTrace.PushContext ("LoadPageViewState");
  646. object sState = LoadPageStateFromPersistenceMedium ();
  647. WebTrace.WriteLine ("sState = '{0}'", sState);
  648. if (sState != null) {
  649. Pair pair = (Pair) sState;
  650. LoadViewStateRecursive (pair.First);
  651. _requiresPostBack = pair.Second as ArrayList;
  652. }
  653. WebTrace.PopContext ();
  654. }
  655. internal void SavePageViewState ()
  656. {
  657. if (!handleViewState)
  658. return;
  659. Pair pair = new Pair ();
  660. pair.First = SaveViewStateRecursive ();
  661. if (_requiresPostBack != null && _requiresPostBack.Count > 0)
  662. pair.Second = _requiresPostBack;
  663. if (pair.First == null && pair.Second == null)
  664. pair = null;
  665. SavePageStateToPersistenceMedium (pair);
  666. }
  667. public virtual void Validate ()
  668. {
  669. if (_validators == null || _validators.Count == 0){
  670. _isValid = true;
  671. return;
  672. }
  673. bool all_valid = true;
  674. foreach (IValidator v in _validators){
  675. v.Validate ();
  676. if (v.IsValid == false)
  677. all_valid = false;
  678. }
  679. if (all_valid)
  680. _isValid = true;
  681. }
  682. [EditorBrowsable (EditorBrowsableState.Advanced)]
  683. public virtual void VerifyRenderingInServerForm (Control control)
  684. {
  685. if (!renderingForm)
  686. throw new HttpException ("Control '" + control.ClientID + " " + control.GetType () +
  687. "' must be rendered within a HtmlForm");
  688. }
  689. #endregion
  690. }
  691. }