Page.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. [EditorBrowsable (EditorBrowsableState.Never)]
  104. protected int CodePage
  105. {
  106. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  107. }
  108. [EditorBrowsable (EditorBrowsableState.Never)]
  109. protected string ContentType
  110. {
  111. set { Response.ContentType = value; }
  112. }
  113. protected override HttpContext Context
  114. {
  115. get { return _context; }
  116. }
  117. [EditorBrowsable (EditorBrowsableState.Never)]
  118. protected string Culture
  119. {
  120. set { _culture = value; }
  121. }
  122. [Browsable (false)]
  123. public override bool EnableViewState
  124. {
  125. get { return _viewState; }
  126. set { _viewState = value; }
  127. }
  128. [EditorBrowsable (EditorBrowsableState.Never)]
  129. protected bool EnableViewStateMac
  130. {
  131. get { return _viewStateMac; }
  132. set { _viewStateMac = value; }
  133. }
  134. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  135. [Browsable (false), DefaultValue ("")]
  136. [WebSysDescription ("The URL of a page used for error redirection.")]
  137. public string ErrorPage
  138. {
  139. get { return _errorPage; }
  140. set { _errorPage = value; }
  141. }
  142. [EditorBrowsable (EditorBrowsableState.Never)]
  143. protected ArrayList FileDependencies
  144. {
  145. set {
  146. if (Response != null)
  147. Response.AddFileDependencies (value);
  148. }
  149. }
  150. [Browsable (false)]
  151. public override string ID
  152. {
  153. get { return _ID; }
  154. set { _ID = value; }
  155. }
  156. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  157. [Browsable (false)]
  158. public bool IsPostBack
  159. {
  160. get {
  161. return (0 == String.Compare (Request.HttpMethod, "POST", true));
  162. }
  163. }
  164. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  165. public bool IsReusable {
  166. get { return false; }
  167. }
  168. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  169. [Browsable (false)]
  170. public bool IsValid
  171. {
  172. get { return _isValid; }
  173. }
  174. [MonoTODO]
  175. [EditorBrowsable (EditorBrowsableState.Never)]
  176. protected int LCID {
  177. set { throw new NotImplementedException (); }
  178. }
  179. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  180. [Browsable (false)]
  181. public HttpRequest Request
  182. {
  183. get { return _context.Request; }
  184. }
  185. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  186. [Browsable (false)]
  187. public HttpResponse Response
  188. {
  189. get { return _context.Response; }
  190. }
  191. [EditorBrowsable (EditorBrowsableState.Never)]
  192. protected string ResponseEncoding
  193. {
  194. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  195. }
  196. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  197. [Browsable (false)]
  198. public HttpServerUtility Server
  199. {
  200. get {
  201. return Context.Server;
  202. }
  203. }
  204. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  205. [Browsable (false)]
  206. public virtual HttpSessionState Session
  207. {
  208. get { return _context.Session; }
  209. }
  210. [Browsable (false)]
  211. public bool SmartNavigation
  212. {
  213. get { return _smartNavigation; }
  214. set { _smartNavigation = value; }
  215. }
  216. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  217. [Browsable (false)]
  218. public TraceContext Trace
  219. {
  220. get { return _trace; }
  221. }
  222. [EditorBrowsable (EditorBrowsableState.Never)]
  223. protected bool TraceEnabled
  224. {
  225. set { _traceEnabled = value; }
  226. }
  227. [EditorBrowsable (EditorBrowsableState.Never)]
  228. protected TraceMode TraceModeValue
  229. {
  230. set { _traceModeValue = value; }
  231. }
  232. [EditorBrowsable (EditorBrowsableState.Never)]
  233. protected int TransactionMode
  234. {
  235. set { _transactionMode = value; }
  236. }
  237. [EditorBrowsable (EditorBrowsableState.Never)]
  238. protected string UICulture
  239. {
  240. set { _UICulture = value; }
  241. }
  242. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  243. [Browsable (false)]
  244. public IPrincipal User
  245. {
  246. get { return _context.User; }
  247. }
  248. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  249. [Browsable (false)]
  250. public ValidatorCollection Validators
  251. {
  252. get {
  253. if (_validators == null)
  254. _validators = new ValidatorCollection ();
  255. return _validators;
  256. }
  257. }
  258. [Browsable (false)]
  259. public override bool Visible
  260. {
  261. get { return base.Visible; }
  262. set { base.Visible = value; }
  263. }
  264. #endregion
  265. #region Methods
  266. [MonoTODO]
  267. [EditorBrowsable (EditorBrowsableState.Never)]
  268. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  269. AsyncCallback cb,
  270. object extraData)
  271. {
  272. throw new NotImplementedException ();
  273. }
  274. [MonoTODO]
  275. [EditorBrowsable (EditorBrowsableState.Never)]
  276. protected void AspCompatEndProcessRequest (IAsyncResult result)
  277. {
  278. throw new NotImplementedException ();
  279. }
  280. [EditorBrowsable (EditorBrowsableState.Advanced)]
  281. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  282. {
  283. return new HtmlTextWriter (tw);
  284. }
  285. [MonoTODO]
  286. [EditorBrowsable (EditorBrowsableState.Never)]
  287. public void DesignerInitialize ()
  288. {
  289. throw new NotImplementedException ();
  290. }
  291. [EditorBrowsable (EditorBrowsableState.Advanced)]
  292. protected virtual NameValueCollection DeterminePostBackMode ()
  293. {
  294. if (_context == null)
  295. return null;
  296. HttpRequest req = _context.Request;
  297. if (req == null)
  298. return null;
  299. NameValueCollection coll = null;
  300. if (IsPostBack)
  301. coll = req.Form;
  302. else
  303. coll = req.QueryString;
  304. if (coll == null || coll ["__VIEWSTATE"] == null)
  305. return null;
  306. return coll;
  307. }
  308. [EditorBrowsable (EditorBrowsableState.Advanced)]
  309. public string GetPostBackClientEvent (Control control, string argument)
  310. {
  311. return GetPostBackEventReference (control, argument);
  312. }
  313. [EditorBrowsable (EditorBrowsableState.Advanced)]
  314. public string GetPostBackClientHyperlink (Control control, string argument)
  315. {
  316. return "javascript:" + GetPostBackEventReference (control, argument);
  317. }
  318. [EditorBrowsable (EditorBrowsableState.Advanced)]
  319. public string GetPostBackEventReference (Control control)
  320. {
  321. return GetPostBackEventReference (control, "");
  322. }
  323. [EditorBrowsable (EditorBrowsableState.Advanced)]
  324. public string GetPostBackEventReference (Control control, string argument)
  325. {
  326. RequiresPostBackScript ();
  327. return String.Format ("__doPostBack('{0}','{1}')", control.UniqueID, argument);
  328. }
  329. internal void RequiresPostBackScript ()
  330. {
  331. requiresPostBackScript = true;
  332. }
  333. [EditorBrowsable (EditorBrowsableState.Never)]
  334. public virtual int GetTypeHashCode ()
  335. {
  336. return 0;
  337. }
  338. [MonoTODO]
  339. [EditorBrowsable (EditorBrowsableState.Never)]
  340. protected virtual void InitOutputCache (int duration,
  341. string varyByHeader,
  342. string varyByCustom,
  343. OutputCacheLocation location,
  344. string varyByParam)
  345. {
  346. HttpCachePolicy cache = _context.Response.Cache;
  347. switch (location) {
  348. case OutputCacheLocation.Any:
  349. cache.SetCacheability (HttpCacheability.Public);
  350. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  351. cache.SetLastModified (_context.Timestamp);
  352. goto case OutputCacheLocation.Server;
  353. case OutputCacheLocation.Client:
  354. cache.SetCacheability (HttpCacheability.Private);
  355. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  356. cache.SetLastModified (_context.Timestamp);
  357. break;
  358. case OutputCacheLocation.Downstream:
  359. cache.SetCacheability (HttpCacheability.Public);
  360. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  361. cache.SetLastModified (_context.Timestamp);
  362. break;
  363. case OutputCacheLocation.Server:
  364. if (varyByCustom != null)
  365. cache.SetVaryByCustom (varyByCustom);
  366. if (varyByParam.Length > 0) {
  367. string[] prms = varyByParam.Split (';');
  368. foreach (string p in prms)
  369. cache.VaryByParams [p.Trim ()] = true;
  370. cache.VaryByParams.IgnoreParams = false;
  371. } else {
  372. cache.VaryByParams.IgnoreParams = true;
  373. }
  374. if (varyByHeader != null) {
  375. string[] hdrs = varyByHeader.Split (';');
  376. foreach (string h in hdrs)
  377. cache.VaryByHeaders [h.Trim ()] = true;
  378. }
  379. _context.Response.CacheResponse (_context.Request);
  380. break;
  381. case OutputCacheLocation.None:
  382. break;
  383. }
  384. cache.SetExpires (_context.Timestamp.AddSeconds (duration));
  385. }
  386. [EditorBrowsable (EditorBrowsableState.Advanced)]
  387. public bool IsClientScriptBlockRegistered (string key)
  388. {
  389. if (clientScriptBlocks == null)
  390. return false;
  391. return clientScriptBlocks.ContainsKey (key);
  392. }
  393. [EditorBrowsable (EditorBrowsableState.Advanced)]
  394. public bool IsStartupScriptRegistered (string key)
  395. {
  396. if (startupScriptBlocks == null)
  397. return false;
  398. return startupScriptBlocks.ContainsKey (key);
  399. }
  400. public string MapPath (string virtualPath)
  401. {
  402. return Request.MapPath (virtualPath);
  403. }
  404. private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  405. {
  406. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
  407. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
  408. writer.WriteLine ();
  409. writer.WriteLine ("<script language=\"javascript\">");
  410. writer.WriteLine ("<!--");
  411. writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
  412. writer.WriteLine ("\t\tvar theform = document.getElementById ('{0}');", formUniqueID);
  413. writer.WriteLine ("\t\ttheform.{0}.value = eventTarget;", postEventSourceID);
  414. writer.WriteLine ("\t\ttheform.{0}.value = eventArgument;", postEventArgumentID);
  415. writer.WriteLine ("\t\ttheform.submit();");
  416. writer.WriteLine ("\t}");
  417. writer.WriteLine ("// -->");
  418. writer.WriteLine ("</script>");
  419. }
  420. static void WriteScripts (HtmlTextWriter writer, Hashtable scripts)
  421. {
  422. if (scripts == null)
  423. return;
  424. foreach (string key in scripts.Values)
  425. writer.WriteLine (key);
  426. }
  427. void WriteHiddenFields (HtmlTextWriter writer)
  428. {
  429. if (hiddenFields == null)
  430. return;
  431. foreach (string key in hiddenFields.Keys) {
  432. string value = hiddenFields [key] as string;
  433. writer.WriteLine ("\n<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />", key, value);
  434. }
  435. hiddenFields = null;
  436. }
  437. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  438. {
  439. if (renderingForm)
  440. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  441. renderingForm = true;
  442. writer.WriteLine ();
  443. WriteHiddenFields (writer);
  444. if (requiresPostBackScript) {
  445. RenderPostBackScript (writer, formUniqueID);
  446. postBackScriptRendered = true;
  447. }
  448. if (handleViewState) {
  449. writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
  450. writer.WriteLine ("value=\"{0}\" />", GetViewStateString ());
  451. }
  452. WriteScripts (writer, clientScriptBlocks);
  453. }
  454. internal string GetViewStateString ()
  455. {
  456. StringWriter sr = new StringWriter ();
  457. LosFormatter fmt = new LosFormatter ();
  458. fmt.Serialize (sr, _savedViewState);
  459. return sr.GetStringBuilder ().ToString ();
  460. }
  461. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  462. {
  463. if (!postBackScriptRendered && requiresPostBackScript)
  464. RenderPostBackScript (writer, formUniqueID);
  465. WriteHiddenFields (writer);
  466. WriteScripts (writer, startupScriptBlocks);
  467. renderingForm = false;
  468. postBackScriptRendered = false;
  469. }
  470. private void ProcessPostData (NameValueCollection data, bool second)
  471. {
  472. if (data == null)
  473. return;
  474. if (_requiresPostBackCopy == null && _requiresPostBack != null)
  475. _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
  476. Hashtable used = new Hashtable ();
  477. foreach (string id in data.AllKeys){
  478. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
  479. continue;
  480. string real_id = id;
  481. int dot = real_id.IndexOf ('.');
  482. if (dot >= 1)
  483. real_id = real_id.Substring (0, dot);
  484. if (real_id == null || used.ContainsKey (real_id))
  485. continue;
  486. used.Add (real_id, real_id);
  487. Control ctrl = FindControl (real_id);
  488. if (ctrl != null){
  489. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  490. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  491. if (pbdh == null) {
  492. if (pbeh != null)
  493. RegisterRequiresRaiseEvent (pbeh);
  494. continue;
  495. }
  496. if (pbdh.LoadPostData (real_id, data) == true) {
  497. if (requiresPostDataChanged == null)
  498. requiresPostDataChanged = new ArrayList ();
  499. requiresPostDataChanged.Add (pbdh);
  500. if (_requiresPostBackCopy != null)
  501. _requiresPostBackCopy.Remove (ctrl.UniqueID);
  502. }
  503. } else if (!second) {
  504. if (secondPostData == null)
  505. secondPostData = new NameValueCollection ();
  506. secondPostData.Add (real_id, data [id]);
  507. }
  508. }
  509. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  510. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  511. foreach (string id in handlers) {
  512. IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
  513. if (pbdh == null)
  514. continue;
  515. _requiresPostBackCopy.Remove (id);
  516. if (pbdh.LoadPostData (id, data)) {
  517. if (requiresPostDataChanged == null)
  518. requiresPostDataChanged = new ArrayList ();
  519. requiresPostDataChanged.Add (pbdh);
  520. }
  521. }
  522. }
  523. }
  524. [EditorBrowsable (EditorBrowsableState.Never)]
  525. public void ProcessRequest (HttpContext context)
  526. {
  527. _context = context;
  528. WebTrace.PushContext ("Page.ProcessRequest ()");
  529. WebTrace.WriteLine ("Entering");
  530. WireupAutomaticEvents ();
  531. WebTrace.WriteLine ("Finished hookup");
  532. //-- Control execution lifecycle in the docs
  533. WebTrace.WriteLine ("FrameworkInitialize");
  534. FrameworkInitialize ();
  535. WebTrace.WriteLine ("InitRecursive");
  536. InitRecursive (null);
  537. renderingForm = false;
  538. if (IsPostBack) {
  539. LoadPageViewState ();
  540. ProcessPostData (DeterminePostBackMode (), false);
  541. }
  542. WebTrace.WriteLine ("LoadRecursive");
  543. LoadRecursive ();
  544. if (IsPostBack) {
  545. ProcessPostData (secondPostData, true);
  546. RaiseChangedEvents ();
  547. RaisePostBackEvents ();
  548. }
  549. WebTrace.WriteLine ("PreRenderRecursiveInternal");
  550. PreRenderRecursiveInternal ();
  551. WebTrace.WriteLine ("SavePageViewState");
  552. SavePageViewState ();
  553. //--
  554. HtmlTextWriter output = new HtmlTextWriter (context.Response.Output);
  555. WebTrace.WriteLine ("RenderControl");
  556. RenderControl (output);
  557. _context = null;
  558. WebTrace.WriteLine ("UnloadRecursive");
  559. UnloadRecursive (true);
  560. WebTrace.WriteLine ("End");
  561. WebTrace.PopContext ();
  562. }
  563. internal void RaisePostBackEvents ()
  564. {
  565. if (requiresRaiseEvent != null) {
  566. RaisePostBackEvent (requiresRaiseEvent, null);
  567. return;
  568. }
  569. NameValueCollection postdata = DeterminePostBackMode ();
  570. if (postdata == null)
  571. return;
  572. string eventTarget = postdata [postEventSourceID];
  573. if (eventTarget == null || eventTarget.Length == 0)
  574. return;
  575. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  576. if (target == null)
  577. return;
  578. string eventArgument = postdata [postEventArgumentID];
  579. RaisePostBackEvent (target, eventArgument);
  580. }
  581. internal void RaiseChangedEvents ()
  582. {
  583. if (requiresPostDataChanged == null)
  584. return;
  585. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  586. ipdh.RaisePostDataChangedEvent ();
  587. requiresPostDataChanged = null;
  588. }
  589. [EditorBrowsable (EditorBrowsableState.Advanced)]
  590. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  591. {
  592. sourceControl.RaisePostBackEvent (eventArgument);
  593. }
  594. [MonoTODO]
  595. [EditorBrowsable (EditorBrowsableState.Advanced)]
  596. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  597. {
  598. throw new NotImplementedException ();
  599. }
  600. [EditorBrowsable (EditorBrowsableState.Advanced)]
  601. public virtual void RegisterClientScriptBlock (string key, string script)
  602. {
  603. if (IsClientScriptBlockRegistered (key))
  604. return;
  605. if (clientScriptBlocks == null)
  606. clientScriptBlocks = new Hashtable ();
  607. clientScriptBlocks.Add (key, script);
  608. }
  609. [EditorBrowsable (EditorBrowsableState.Advanced)]
  610. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  611. {
  612. if (hiddenFields == null)
  613. hiddenFields = new Hashtable ();
  614. if (!hiddenFields.ContainsKey (hiddenFieldName))
  615. hiddenFields.Add (hiddenFieldName, hiddenFieldInitialValue);
  616. }
  617. [MonoTODO]
  618. public void RegisterClientScriptFile (string a, string b, string c)
  619. {
  620. throw new NotImplementedException ();
  621. }
  622. [MonoTODO]
  623. [EditorBrowsable (EditorBrowsableState.Advanced)]
  624. public void RegisterOnSubmitStatement (string key, string script)
  625. {
  626. if (submitStatements == null)
  627. submitStatements = new Hashtable ();
  628. if (submitStatements.ContainsKey (key))
  629. return;
  630. submitStatements.Add (key, script);
  631. }
  632. [EditorBrowsable (EditorBrowsableState.Advanced)]
  633. public void RegisterRequiresPostBack (Control control)
  634. {
  635. if (_requiresPostBack == null)
  636. _requiresPostBack = new ArrayList ();
  637. _requiresPostBack.Add (control.UniqueID);
  638. }
  639. [EditorBrowsable (EditorBrowsableState.Advanced)]
  640. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  641. {
  642. requiresRaiseEvent = control;
  643. }
  644. [EditorBrowsable (EditorBrowsableState.Advanced)]
  645. public virtual void RegisterStartupScript (string key, string script)
  646. {
  647. if (IsStartupScriptRegistered (key))
  648. return;
  649. if (startupScriptBlocks == null)
  650. startupScriptBlocks = new Hashtable ();
  651. startupScriptBlocks.Add (key, script);
  652. }
  653. [EditorBrowsable (EditorBrowsableState.Advanced)]
  654. public void RegisterViewStateHandler ()
  655. {
  656. handleViewState = true;
  657. }
  658. [EditorBrowsable (EditorBrowsableState.Advanced)]
  659. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  660. {
  661. _savedViewState = viewState;
  662. }
  663. [EditorBrowsable (EditorBrowsableState.Advanced)]
  664. protected virtual object LoadPageStateFromPersistenceMedium ()
  665. {
  666. NameValueCollection postdata = DeterminePostBackMode ();
  667. string view_state;
  668. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  669. return null;
  670. _savedViewState = null;
  671. LosFormatter fmt = new LosFormatter ();
  672. try {
  673. _savedViewState = fmt.Deserialize (view_state);
  674. } catch (Exception e) {
  675. throw new HttpException ("Error restoring page viewstate.\n", e);
  676. }
  677. return _savedViewState;
  678. }
  679. internal void LoadPageViewState()
  680. {
  681. WebTrace.PushContext ("LoadPageViewState");
  682. object sState = LoadPageStateFromPersistenceMedium ();
  683. WebTrace.WriteLine ("sState = '{0}'", sState);
  684. if (sState != null) {
  685. Pair pair = (Pair) sState;
  686. LoadViewStateRecursive (pair.First);
  687. _requiresPostBack = pair.Second as ArrayList;
  688. }
  689. WebTrace.PopContext ();
  690. }
  691. internal void SavePageViewState ()
  692. {
  693. if (!handleViewState)
  694. return;
  695. Pair pair = new Pair ();
  696. pair.First = SaveViewStateRecursive ();
  697. if (_requiresPostBack != null && _requiresPostBack.Count > 0)
  698. pair.Second = _requiresPostBack;
  699. if (pair.First == null && pair.Second == null)
  700. pair = null;
  701. SavePageStateToPersistenceMedium (pair);
  702. }
  703. public virtual void Validate ()
  704. {
  705. if (_validators == null || _validators.Count == 0){
  706. _isValid = true;
  707. return;
  708. }
  709. bool all_valid = true;
  710. foreach (IValidator v in _validators){
  711. v.Validate ();
  712. if (v.IsValid == false)
  713. all_valid = false;
  714. }
  715. if (all_valid)
  716. _isValid = true;
  717. }
  718. [EditorBrowsable (EditorBrowsableState.Advanced)]
  719. public virtual void VerifyRenderingInServerForm (Control control)
  720. {
  721. if (!renderingForm)
  722. throw new HttpException ("Control '" + control.ClientID + " " + control.GetType () +
  723. "' must be rendered within a HtmlForm");
  724. }
  725. #endregion
  726. #if NET_1_2
  727. public string GetWebResourceUrl(Type type, string resourceName)
  728. {
  729. if (type == null)
  730. throw new ArgumentNullException ("type");
  731. if (resourceName == null || resourceName.Length == 0)
  732. throw new ArgumentNullException ("type");
  733. return System.Web.Handlers.AssemblyResourceLoader.GetResourceUrl (type, resourceName);
  734. }
  735. #endif
  736. }
  737. }