Page.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  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. // Copyright (C) 2003,2005 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Collections;
  33. using System.Collections.Specialized;
  34. using System.ComponentModel;
  35. using System.ComponentModel.Design;
  36. using System.ComponentModel.Design.Serialization;
  37. using System.Globalization;
  38. using System.IO;
  39. using System.Security.Cryptography;
  40. using System.Security.Permissions;
  41. using System.Security.Principal;
  42. using System.Text;
  43. using System.Threading;
  44. using System.Web;
  45. using System.Web.Caching;
  46. using System.Web.Configuration;
  47. using System.Web.SessionState;
  48. using System.Web.Util;
  49. using System.Web.UI.HtmlControls;
  50. using System.Web.UI.WebControls;
  51. #if NET_2_0
  52. using System.Web.UI.Adapters;
  53. #endif
  54. namespace System.Web.UI
  55. {
  56. // CAS
  57. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  58. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  59. #if !NET_2_0
  60. [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
  61. #endif
  62. [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
  63. [ToolboxItem (false)]
  64. #if NET_2_0
  65. [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
  66. #else
  67. [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
  68. #endif
  69. public class Page : TemplateControl, IHttpHandler
  70. {
  71. private bool _eventValidation = true;
  72. private bool _viewState = true;
  73. private bool _viewStateMac;
  74. private string _errorPage;
  75. private bool is_validated;
  76. private bool _smartNavigation;
  77. private int _transactionMode;
  78. private HttpContext _context;
  79. private ValidatorCollection _validators;
  80. private bool renderingForm;
  81. private object _savedViewState;
  82. private ArrayList _requiresPostBack;
  83. private ArrayList _requiresPostBackCopy;
  84. private ArrayList requiresPostDataChanged;
  85. private IPostBackEventHandler requiresRaiseEvent;
  86. private NameValueCollection secondPostData;
  87. private bool requiresPostBackScript;
  88. private bool postBackScriptRendered;
  89. bool handleViewState;
  90. string viewStateUserKey;
  91. NameValueCollection _requestValueCollection;
  92. string clientTarget;
  93. ClientScriptManager scriptManager;
  94. bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
  95. [EditorBrowsable (EditorBrowsableState.Never)]
  96. #if NET_2_0
  97. public
  98. #else
  99. protected
  100. #endif
  101. const string postEventArgumentID = "__EVENTARGUMENT";
  102. [EditorBrowsable (EditorBrowsableState.Never)]
  103. #if NET_2_0
  104. public
  105. #else
  106. protected
  107. #endif
  108. const string postEventSourceID = "__EVENTTARGET";
  109. #if NET_2_0
  110. internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
  111. internal const string CallbackSourceID = "__CALLBACKTARGET";
  112. internal const string PreviousPageID = "__PREVIOUSPAGE";
  113. HtmlHead htmlHeader;
  114. MasterPage masterPage;
  115. string masterPageFile;
  116. Page previousPage;
  117. bool isCrossPagePostBack;
  118. ArrayList requireStateControls;
  119. Hashtable _validatorsByGroup;
  120. HtmlForm _form;
  121. string _title;
  122. string _theme;
  123. string _styleSheetTheme;
  124. #endif
  125. #region Constructor
  126. public Page ()
  127. {
  128. scriptManager = new ClientScriptManager (this);
  129. Page = this;
  130. ID = "__Page";
  131. }
  132. #endregion
  133. #region Properties
  134. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  135. [Browsable (false)]
  136. public HttpApplicationState Application
  137. {
  138. get {
  139. if (_context == null)
  140. return null;
  141. return _context.Application;
  142. }
  143. }
  144. [EditorBrowsable (EditorBrowsableState.Never)]
  145. protected bool AspCompatMode
  146. {
  147. #if NET_2_0
  148. get { return false; }
  149. #endif
  150. set { throw new NotImplementedException (); }
  151. }
  152. [EditorBrowsable (EditorBrowsableState.Never)]
  153. #if NET_2_0
  154. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  155. [BrowsableAttribute (false)]
  156. public bool Buffer
  157. {
  158. get { return Response.BufferOutput; }
  159. set { Response.BufferOutput = value; }
  160. }
  161. #else
  162. protected bool Buffer
  163. {
  164. set { Response.BufferOutput = value; }
  165. }
  166. #endif
  167. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  168. [Browsable (false)]
  169. public Cache Cache
  170. {
  171. get {
  172. if (_context == null)
  173. throw new HttpException ("No cache available without a context.");
  174. return _context.Cache;
  175. }
  176. }
  177. #if NET_2_0
  178. [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
  179. #endif
  180. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  181. [Browsable (false), DefaultValue ("")]
  182. [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
  183. public string ClientTarget
  184. {
  185. get { return (clientTarget == null) ? "" : clientTarget; }
  186. set {
  187. clientTarget = value;
  188. if (value == "")
  189. clientTarget = null;
  190. }
  191. }
  192. [EditorBrowsable (EditorBrowsableState.Never)]
  193. #if NET_2_0
  194. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  195. [BrowsableAttribute (false)]
  196. public int CodePage
  197. {
  198. get { return Response.ContentEncoding.CodePage; }
  199. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  200. }
  201. #else
  202. protected int CodePage
  203. {
  204. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  205. }
  206. #endif
  207. [EditorBrowsable (EditorBrowsableState.Never)]
  208. #if NET_2_0
  209. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  210. [BrowsableAttribute (false)]
  211. public string ContentType
  212. {
  213. get { return Response.ContentType; }
  214. set { Response.ContentType = value; }
  215. }
  216. #else
  217. protected string ContentType
  218. {
  219. set { Response.ContentType = value; }
  220. }
  221. #endif
  222. protected override HttpContext Context
  223. {
  224. get {
  225. if (_context == null)
  226. return HttpContext.Current;
  227. return _context;
  228. }
  229. }
  230. #if NET_2_0
  231. [EditorBrowsable (EditorBrowsableState.Advanced)]
  232. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  233. [BrowsableAttribute (false)]
  234. public string Culture
  235. {
  236. get { return Thread.CurrentThread.CurrentCulture.Name; }
  237. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  238. }
  239. #else
  240. [EditorBrowsable (EditorBrowsableState.Never)]
  241. protected string Culture
  242. {
  243. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  244. }
  245. #endif
  246. #if NET_2_0
  247. public virtual bool EnableEventValidation {
  248. get { return _eventValidation; }
  249. set { _eventValidation = value;}
  250. }
  251. #endif
  252. [Browsable (false)]
  253. public override bool EnableViewState
  254. {
  255. get { return _viewState; }
  256. set { _viewState = value; }
  257. }
  258. #if NET_2_0
  259. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  260. [BrowsableAttribute (false)]
  261. #endif
  262. [EditorBrowsable (EditorBrowsableState.Never)]
  263. #if NET_2_0
  264. public
  265. #else
  266. protected
  267. #endif
  268. bool EnableViewStateMac
  269. {
  270. get { return _viewStateMac; }
  271. set { _viewStateMac = value; }
  272. }
  273. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  274. [Browsable (false), DefaultValue ("")]
  275. [WebSysDescription ("The URL of a page used for error redirection.")]
  276. public string ErrorPage
  277. {
  278. get { return _errorPage; }
  279. set {
  280. _errorPage = value;
  281. if (_context != null)
  282. _context.ErrorPage = value;
  283. }
  284. }
  285. #if NET_2_0
  286. [Obsolete]
  287. #endif
  288. [EditorBrowsable (EditorBrowsableState.Never)]
  289. protected ArrayList FileDependencies
  290. {
  291. set {
  292. if (Response != null)
  293. Response.AddFileDependencies (value);
  294. }
  295. }
  296. [Browsable (false)]
  297. #if NET_2_0
  298. [EditorBrowsable (EditorBrowsableState.Never)]
  299. #endif
  300. public override string ID
  301. {
  302. get { return base.ID; }
  303. set { base.ID = value; }
  304. }
  305. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  306. [Browsable (false)]
  307. public bool IsPostBack
  308. {
  309. get {
  310. return _requestValueCollection != null;
  311. }
  312. }
  313. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  314. public bool IsReusable {
  315. get { return false; }
  316. }
  317. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  318. [Browsable (false)]
  319. public bool IsValid {
  320. get {
  321. if (!is_validated)
  322. throw new HttpException (Locale.GetText ("Page hasn't been validated."));
  323. return ValidateCollection (_validators);
  324. }
  325. }
  326. [EditorBrowsable (EditorBrowsableState.Never)]
  327. #if NET_2_0
  328. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  329. [BrowsableAttribute (false)]
  330. public int LCID {
  331. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  332. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  333. }
  334. #else
  335. protected int LCID {
  336. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  337. }
  338. #endif
  339. #if NET_2_0
  340. public PageAdapter PageAdapter {
  341. get {
  342. return (PageAdapter)Adapter;
  343. }
  344. }
  345. #endif
  346. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  347. [Browsable (false)]
  348. public HttpRequest Request
  349. {
  350. get {
  351. if (_context != null)
  352. return _context.Request;
  353. throw new HttpException("Request is not available without context");
  354. }
  355. }
  356. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  357. [Browsable (false)]
  358. public HttpResponse Response
  359. {
  360. get {
  361. if (_context != null)
  362. return _context.Response;
  363. throw new HttpException ("Response is not available without context");
  364. }
  365. }
  366. [EditorBrowsable (EditorBrowsableState.Never)]
  367. #if NET_2_0
  368. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  369. [BrowsableAttribute (false)]
  370. public string ResponseEncoding
  371. {
  372. get { return Response.ContentEncoding.WebName; }
  373. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  374. }
  375. #else
  376. protected string ResponseEncoding
  377. {
  378. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  379. }
  380. #endif
  381. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  382. [Browsable (false)]
  383. public HttpServerUtility Server
  384. {
  385. get {
  386. return Context.Server;
  387. }
  388. }
  389. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  390. [Browsable (false)]
  391. public virtual HttpSessionState Session
  392. {
  393. get {
  394. if (_context == null)
  395. throw new HttpException ("Session is not available without context");
  396. if (_context.Session == null)
  397. throw new HttpException ("Session state can only be used " +
  398. "when enableSessionState is set to true, either " +
  399. "in a configuration file or in the Page directive.");
  400. return _context.Session;
  401. }
  402. }
  403. #if NET_2_0
  404. [FilterableAttribute (false)]
  405. [Obsolete]
  406. #endif
  407. [Browsable (false)]
  408. public bool SmartNavigation
  409. {
  410. get { return _smartNavigation; }
  411. set { _smartNavigation = value; }
  412. }
  413. #if NET_2_0
  414. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  415. [Filterable (false)]
  416. [Browsable (false)]
  417. public virtual string StyleSheetTheme {
  418. get { return _styleSheetTheme; }
  419. set { _styleSheetTheme = value; }
  420. }
  421. [Browsable (false)]
  422. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  423. public virtual string Theme {
  424. get { return _theme; }
  425. set { _theme = value; }
  426. }
  427. void InitializeStyleSheet ()
  428. {
  429. if (_styleSheetTheme != null && _styleSheetTheme != "")
  430. _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("./App_Themes/" + _styleSheetTheme + "/", _context);
  431. }
  432. void InitializeTheme ()
  433. {
  434. if (_theme != null && _theme != "") {
  435. _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("./App_Themes/" + _theme + "/", _context);
  436. ApplyThemeRecursive ();
  437. }
  438. }
  439. #endif
  440. #if NET_2_0
  441. [Localizable (true)]
  442. [Bindable (true)]
  443. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  444. public string Title {
  445. get { return _title; }
  446. set { _title = value; }
  447. }
  448. #endif
  449. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  450. [Browsable (false)]
  451. public TraceContext Trace
  452. {
  453. get { return Context.Trace; }
  454. }
  455. [EditorBrowsable (EditorBrowsableState.Never)]
  456. #if NET_2_0
  457. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  458. [BrowsableAttribute (false)]
  459. public bool TraceEnabled
  460. {
  461. get { return Trace.IsEnabled; }
  462. set { Trace.IsEnabled = value; }
  463. }
  464. #else
  465. protected bool TraceEnabled
  466. {
  467. set { Trace.IsEnabled = value; }
  468. }
  469. #endif
  470. [EditorBrowsable (EditorBrowsableState.Never)]
  471. #if NET_2_0
  472. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  473. [BrowsableAttribute (false)]
  474. public TraceMode TraceModeValue
  475. {
  476. get { return Trace.TraceMode; }
  477. set { Trace.TraceMode = value; }
  478. }
  479. #else
  480. protected TraceMode TraceModeValue
  481. {
  482. set { Trace.TraceMode = value; }
  483. }
  484. #endif
  485. [EditorBrowsable (EditorBrowsableState.Never)]
  486. protected int TransactionMode
  487. {
  488. #if NET_2_0
  489. get { return _transactionMode; }
  490. #endif
  491. set { _transactionMode = value; }
  492. }
  493. #if NET_2_0
  494. [EditorBrowsable (EditorBrowsableState.Advanced)]
  495. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  496. [BrowsableAttribute (false)]
  497. public string UICulture
  498. {
  499. get { return Thread.CurrentThread.CurrentUICulture.Name; }
  500. set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
  501. }
  502. #else
  503. [EditorBrowsable (EditorBrowsableState.Never)]
  504. protected string UICulture
  505. {
  506. set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
  507. }
  508. #endif
  509. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  510. [Browsable (false)]
  511. public IPrincipal User
  512. {
  513. get { return Context.User; }
  514. }
  515. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  516. [Browsable (false)]
  517. public ValidatorCollection Validators
  518. {
  519. get {
  520. if (_validators == null)
  521. _validators = new ValidatorCollection ();
  522. return _validators;
  523. }
  524. }
  525. [MonoTODO ("Use this when encrypting/decrypting ViewState")]
  526. [Browsable (false)]
  527. public string ViewStateUserKey {
  528. get { return viewStateUserKey; }
  529. set { viewStateUserKey = value; }
  530. }
  531. [Browsable (false)]
  532. public override bool Visible
  533. {
  534. get { return base.Visible; }
  535. set { base.Visible = value; }
  536. }
  537. #endregion
  538. #region Methods
  539. [EditorBrowsable (EditorBrowsableState.Never)]
  540. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  541. AsyncCallback cb,
  542. object extraData)
  543. {
  544. throw new NotImplementedException ();
  545. }
  546. [EditorBrowsable (EditorBrowsableState.Never)]
  547. protected void AspCompatEndProcessRequest (IAsyncResult result)
  548. {
  549. throw new NotImplementedException ();
  550. }
  551. [EditorBrowsable (EditorBrowsableState.Advanced)]
  552. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  553. {
  554. return new HtmlTextWriter (tw);
  555. }
  556. [EditorBrowsable (EditorBrowsableState.Never)]
  557. public void DesignerInitialize ()
  558. {
  559. InitRecursive (null);
  560. }
  561. [EditorBrowsable (EditorBrowsableState.Advanced)]
  562. protected virtual NameValueCollection DeterminePostBackMode ()
  563. {
  564. if (_context == null)
  565. return null;
  566. HttpRequest req = _context.Request;
  567. if (req == null)
  568. return null;
  569. NameValueCollection coll = null;
  570. if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
  571. coll = req.Form;
  572. WebROCollection c = (WebROCollection) coll;
  573. allow_load = !c.GotID;
  574. if (allow_load) {
  575. c.ID = GetTypeHashCode ();
  576. } else {
  577. allow_load = (c.ID == GetTypeHashCode ());
  578. }
  579. } else {
  580. coll = req.QueryString;
  581. }
  582. if (coll == null || coll ["__VIEWSTATE"] == null)
  583. return null;
  584. return coll;
  585. }
  586. #if NET_2_0
  587. public override Control FindControl (string id) {
  588. if (id == ID)
  589. return this;
  590. else
  591. return base.FindControl (id);
  592. }
  593. #endif
  594. #if NET_2_0
  595. [Obsolete]
  596. #endif
  597. [EditorBrowsable (EditorBrowsableState.Advanced)]
  598. public string GetPostBackClientEvent (Control control, string argument)
  599. {
  600. return scriptManager.GetPostBackEventReference (control, argument);
  601. }
  602. #if NET_2_0
  603. [Obsolete]
  604. #endif
  605. [EditorBrowsable (EditorBrowsableState.Advanced)]
  606. public string GetPostBackClientHyperlink (Control control, string argument)
  607. {
  608. return scriptManager.GetPostBackClientHyperlink (control, argument);
  609. }
  610. #if NET_2_0
  611. [Obsolete]
  612. #endif
  613. [EditorBrowsable (EditorBrowsableState.Advanced)]
  614. public string GetPostBackEventReference (Control control)
  615. {
  616. return scriptManager.GetPostBackEventReference (control, "");
  617. }
  618. #if NET_2_0
  619. [Obsolete]
  620. #endif
  621. [EditorBrowsable (EditorBrowsableState.Advanced)]
  622. public string GetPostBackEventReference (Control control, string argument)
  623. {
  624. return scriptManager.GetPostBackEventReference (control, argument);
  625. }
  626. internal void RequiresPostBackScript ()
  627. {
  628. requiresPostBackScript = true;
  629. }
  630. [EditorBrowsable (EditorBrowsableState.Never)]
  631. public virtual int GetTypeHashCode ()
  632. {
  633. return 0;
  634. }
  635. [EditorBrowsable (EditorBrowsableState.Never)]
  636. protected virtual void InitOutputCache (int duration,
  637. string varyByHeader,
  638. string varyByCustom,
  639. OutputCacheLocation location,
  640. string varyByParam)
  641. {
  642. HttpCachePolicy cache = _context.Response.Cache;
  643. bool set_vary = false;
  644. switch (location) {
  645. case OutputCacheLocation.Any:
  646. cache.SetCacheability (HttpCacheability.Public);
  647. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  648. cache.SetLastModified (_context.Timestamp);
  649. set_vary = true;
  650. break;
  651. case OutputCacheLocation.Client:
  652. cache.SetCacheability (HttpCacheability.Private);
  653. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  654. cache.SetLastModified (_context.Timestamp);
  655. break;
  656. case OutputCacheLocation.Downstream:
  657. cache.SetCacheability (HttpCacheability.Public);
  658. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  659. cache.SetLastModified (_context.Timestamp);
  660. break;
  661. case OutputCacheLocation.Server:
  662. cache.SetCacheability (HttpCacheability.Server);
  663. set_vary = true;
  664. break;
  665. case OutputCacheLocation.None:
  666. break;
  667. }
  668. if (set_vary) {
  669. if (varyByCustom != null)
  670. cache.SetVaryByCustom (varyByCustom);
  671. if (varyByParam != null && varyByParam.Length > 0) {
  672. string[] prms = varyByParam.Split (';');
  673. foreach (string p in prms)
  674. cache.VaryByParams [p.Trim ()] = true;
  675. cache.VaryByParams.IgnoreParams = false;
  676. } else {
  677. cache.VaryByParams.IgnoreParams = true;
  678. }
  679. if (varyByHeader != null && varyByHeader.Length > 0) {
  680. string[] hdrs = varyByHeader.Split (';');
  681. foreach (string h in hdrs)
  682. cache.VaryByHeaders [h.Trim ()] = true;
  683. }
  684. }
  685. cache.Duration = duration;
  686. cache.SetExpires (_context.Timestamp.AddSeconds (duration));
  687. }
  688. #if NET_2_0
  689. [Obsolete]
  690. #else
  691. [EditorBrowsable (EditorBrowsableState.Advanced)]
  692. #endif
  693. public bool IsClientScriptBlockRegistered (string key)
  694. {
  695. return scriptManager.IsClientScriptBlockRegistered (key);
  696. }
  697. #if NET_2_0
  698. [Obsolete]
  699. #else
  700. [EditorBrowsable (EditorBrowsableState.Advanced)]
  701. #endif
  702. public bool IsStartupScriptRegistered (string key)
  703. {
  704. return scriptManager.IsStartupScriptRegistered (key);
  705. }
  706. public string MapPath (string virtualPath)
  707. {
  708. return Request.MapPath (virtualPath);
  709. }
  710. private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  711. {
  712. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
  713. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
  714. writer.WriteLine ();
  715. writer.WriteLine ("<script language=\"javascript\">");
  716. writer.WriteLine ("<!--");
  717. if (Request.Browser.Browser == ("Netscape") && Request.Browser.MajorVersion == 4)
  718. writer.WriteLine ("\tvar theForm = document.{0};", formUniqueID);
  719. else
  720. writer.WriteLine ("\tvar theForm = document.getElementById ('{0}');", formUniqueID);
  721. writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
  722. writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
  723. writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
  724. writer.WriteLine ("\t\ttheForm.submit();");
  725. writer.WriteLine ("\t}");
  726. writer.WriteLine ("// -->");
  727. writer.WriteLine ("</script>");
  728. }
  729. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  730. {
  731. if (renderingForm)
  732. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  733. renderingForm = true;
  734. writer.WriteLine ();
  735. scriptManager.WriteHiddenFields (writer);
  736. if (requiresPostBackScript) {
  737. RenderPostBackScript (writer, formUniqueID);
  738. postBackScriptRendered = true;
  739. }
  740. if (handleViewState) {
  741. string vs = GetViewStateString ();
  742. writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
  743. writer.WriteLine ("value=\"{0}\" />", vs);
  744. }
  745. scriptManager.WriteClientScriptBlocks (writer);
  746. }
  747. LosFormatter GetFormatter ()
  748. {
  749. #if NET_2_0
  750. PagesSection config = (PagesSection) WebConfigurationManager.GetSection ("system.web/pages");
  751. #else
  752. PagesConfiguration config = PagesConfiguration.GetInstance (_context);
  753. #endif
  754. byte [] vkey = null;
  755. if (config.EnableViewStateMac) {
  756. #if NET_2_0
  757. MachineKeySection mconfig = (MachineKeySection) WebConfigurationManager.GetSection ("system.web/machineKey");
  758. vkey = mconfig.ValidationKeyBytes;
  759. #else
  760. MachineKeyConfig mconfig = HttpContext.GetAppConfig ("system.web/machineKey") as MachineKeyConfig;
  761. vkey = mconfig.ValidationKey;
  762. #endif
  763. }
  764. return new LosFormatter (config.EnableViewStateMac, vkey);
  765. }
  766. string GetViewStateString ()
  767. {
  768. if (_savedViewState == null)
  769. return null;
  770. LosFormatter fmt = GetFormatter ();
  771. MemoryStream ms = new MemoryStream ();
  772. fmt.Serialize (ms, _savedViewState);
  773. return Convert.ToBase64String (ms.GetBuffer (), 0, (int) ms.Length);
  774. }
  775. internal object GetSavedViewState ()
  776. {
  777. return _savedViewState;
  778. }
  779. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  780. {
  781. scriptManager.WriteArrayDeclares (writer);
  782. if (!postBackScriptRendered && requiresPostBackScript)
  783. RenderPostBackScript (writer, formUniqueID);
  784. scriptManager.WriteHiddenFields (writer);
  785. scriptManager.WriteClientScriptIncludes (writer);
  786. scriptManager.WriteStartupScriptBlocks (writer);
  787. renderingForm = false;
  788. postBackScriptRendered = false;
  789. }
  790. private void ProcessPostData (NameValueCollection data, bool second)
  791. {
  792. if (data == null)
  793. return;
  794. if (_requiresPostBackCopy == null && _requiresPostBack != null)
  795. _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
  796. Hashtable used = new Hashtable ();
  797. foreach (string id in data.AllKeys){
  798. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
  799. continue;
  800. string real_id = id;
  801. int dot = real_id.IndexOf ('.');
  802. if (dot >= 1)
  803. real_id = real_id.Substring (0, dot);
  804. if (real_id == null || used.ContainsKey (real_id))
  805. continue;
  806. used.Add (real_id, real_id);
  807. Control ctrl = FindControl (real_id);
  808. if (ctrl != null){
  809. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  810. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  811. if (pbdh == null) {
  812. if (pbeh != null)
  813. RegisterRequiresRaiseEvent (pbeh);
  814. continue;
  815. }
  816. if (pbdh.LoadPostData (real_id, data) == true) {
  817. if (requiresPostDataChanged == null)
  818. requiresPostDataChanged = new ArrayList ();
  819. requiresPostDataChanged.Add (pbdh);
  820. if (_requiresPostBackCopy != null)
  821. _requiresPostBackCopy.Remove (ctrl.UniqueID);
  822. }
  823. } else if (!second) {
  824. if (secondPostData == null)
  825. secondPostData = new NameValueCollection ();
  826. secondPostData.Add (real_id, data [id]);
  827. }
  828. }
  829. ArrayList list1 = null;
  830. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  831. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  832. foreach (string id in handlers) {
  833. IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
  834. if (pbdh != null) {
  835. _requiresPostBackCopy.Remove (id);
  836. if (pbdh.LoadPostData (id, data)) {
  837. if (requiresPostDataChanged == null)
  838. requiresPostDataChanged = new ArrayList ();
  839. requiresPostDataChanged.Add (pbdh);
  840. }
  841. } else if (second) {
  842. if (list1 == null)
  843. list1 = new ArrayList ();
  844. list1.Add (id);
  845. }
  846. }
  847. }
  848. _requiresPostBack = list1;
  849. }
  850. [EditorBrowsable (EditorBrowsableState.Never)]
  851. #if NET_2_0 || TARGET_JVM
  852. public virtual void ProcessRequest (HttpContext context)
  853. #else
  854. public void ProcessRequest (HttpContext context)
  855. #endif
  856. {
  857. _context = context;
  858. if (clientTarget != null)
  859. Request.ClientTarget = clientTarget;
  860. WireupAutomaticEvents ();
  861. //-- Control execution lifecycle in the docs
  862. // Save culture information because it can be modified in FrameworkInitialize()
  863. CultureInfo culture = Thread.CurrentThread.CurrentCulture;
  864. CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
  865. FrameworkInitialize ();
  866. context.ErrorPage = _errorPage;
  867. try {
  868. InternalProcessRequest ();
  869. } catch (ThreadAbortException) {
  870. // Do nothing, just ignore it by now.
  871. } catch (Exception e) {
  872. context.AddError (e); // OnError might access LastError
  873. OnError (EventArgs.Empty);
  874. context.ClearError (e);
  875. // We want to remove that error, as we're rethrowing to stop
  876. // further processing.
  877. throw;
  878. } finally {
  879. try {
  880. UnloadRecursive (true);
  881. } catch {}
  882. if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
  883. Thread.CurrentThread.CurrentCulture = culture;
  884. if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
  885. Thread.CurrentThread.CurrentUICulture = uiculture;
  886. }
  887. }
  888. #if NET_2_0
  889. internal void ProcessCrossPagePostBack (HttpContext context)
  890. {
  891. isCrossPagePostBack = true;
  892. ProcessRequest (context);
  893. }
  894. #endif
  895. void InternalProcessRequest ()
  896. {
  897. _requestValueCollection = this.DeterminePostBackMode();
  898. #if NET_2_0
  899. if (!IsCrossPagePostBack)
  900. LoadPreviousPageReference ();
  901. OnPreInit (EventArgs.Empty);
  902. InitializeTheme ();
  903. #endif
  904. Trace.Write ("aspx.page", "Begin Init");
  905. InitRecursive (null);
  906. Trace.Write ("aspx.page", "End Init");
  907. #if NET_2_0
  908. OnInitComplete (EventArgs.Empty);
  909. ApplyMasterPage ();
  910. if (_title != null && htmlHeader != null)
  911. htmlHeader.Title = _title;
  912. #endif
  913. renderingForm = false;
  914. if (IsPostBack) {
  915. Trace.Write ("aspx.page", "Begin LoadViewState");
  916. LoadPageViewState ();
  917. Trace.Write ("aspx.page", "End LoadViewState");
  918. Trace.Write ("aspx.page", "Begin ProcessPostData");
  919. ProcessPostData (_requestValueCollection, false);
  920. Trace.Write ("aspx.page", "End ProcessPostData");
  921. }
  922. #if NET_2_0
  923. if (IsCrossPagePostBack)
  924. return;
  925. OnPreLoad (EventArgs.Empty);
  926. #endif
  927. LoadRecursive ();
  928. if (IsPostBack) {
  929. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  930. ProcessPostData (secondPostData, true);
  931. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  932. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  933. RaiseChangedEvents ();
  934. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  935. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  936. RaisePostBackEvents ();
  937. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  938. }
  939. #if NET_2_0
  940. OnLoadComplete (EventArgs.Empty);
  941. if (IsCallback) {
  942. string result = ProcessCallbackData ();
  943. HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
  944. callbackOutput.Write (result);
  945. callbackOutput.Flush ();
  946. return;
  947. }
  948. #endif
  949. Trace.Write ("aspx.page", "Begin PreRender");
  950. PreRenderRecursiveInternal ();
  951. Trace.Write ("aspx.page", "End PreRender");
  952. #if NET_2_0
  953. OnPreRenderComplete (EventArgs.Empty);
  954. #endif
  955. Trace.Write ("aspx.page", "Begin SaveViewState");
  956. SavePageViewState ();
  957. Trace.Write ("aspx.page", "End SaveViewState");
  958. #if NET_2_0
  959. OnSaveStateComplete (EventArgs.Empty);
  960. #endif
  961. //--
  962. Trace.Write ("aspx.page", "Begin Render");
  963. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  964. RenderControl (output);
  965. Trace.Write ("aspx.page", "End Render");
  966. RenderTrace (output);
  967. }
  968. private void RenderTrace (HtmlTextWriter output)
  969. {
  970. TraceManager traceManager = HttpRuntime.TraceManager;
  971. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  972. return;
  973. Trace.SaveData ();
  974. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  975. return;
  976. if (!traceManager.LocalOnly || Context.Request.IsLocal)
  977. Trace.Render (output);
  978. }
  979. void RaisePostBackEvents ()
  980. {
  981. if (requiresRaiseEvent != null) {
  982. RaisePostBackEvent (requiresRaiseEvent, null);
  983. return;
  984. }
  985. NameValueCollection postdata = _requestValueCollection;
  986. if (postdata == null)
  987. return;
  988. string eventTarget = postdata [postEventSourceID];
  989. if (eventTarget == null || eventTarget.Length == 0) {
  990. Validate ();
  991. return;
  992. }
  993. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  994. if (target == null)
  995. return;
  996. string eventArgument = postdata [postEventArgumentID];
  997. RaisePostBackEvent (target, eventArgument);
  998. }
  999. internal void RaiseChangedEvents ()
  1000. {
  1001. if (requiresPostDataChanged == null)
  1002. return;
  1003. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1004. ipdh.RaisePostDataChangedEvent ();
  1005. requiresPostDataChanged = null;
  1006. }
  1007. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1008. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1009. {
  1010. sourceControl.RaisePostBackEvent (eventArgument);
  1011. }
  1012. #if NET_2_0
  1013. [Obsolete]
  1014. #endif
  1015. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1016. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1017. {
  1018. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1019. }
  1020. #if NET_2_0
  1021. [Obsolete]
  1022. #endif
  1023. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1024. public virtual void RegisterClientScriptBlock (string key, string script)
  1025. {
  1026. scriptManager.RegisterClientScriptBlock (key, script);
  1027. }
  1028. #if NET_2_0
  1029. [Obsolete]
  1030. #endif
  1031. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1032. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1033. {
  1034. scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  1035. }
  1036. [MonoTODO("Used in HtmlForm")]
  1037. internal void RegisterClientScriptFile (string a, string b, string c)
  1038. {
  1039. throw new NotImplementedException ();
  1040. }
  1041. #if NET_2_0
  1042. [Obsolete]
  1043. #endif
  1044. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1045. public void RegisterOnSubmitStatement (string key, string script)
  1046. {
  1047. scriptManager.RegisterOnSubmitStatement (key, script);
  1048. }
  1049. internal string GetSubmitStatements ()
  1050. {
  1051. return scriptManager.WriteSubmitStatements ();
  1052. }
  1053. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1054. public void RegisterRequiresPostBack (Control control)
  1055. {
  1056. if (_requiresPostBack == null)
  1057. _requiresPostBack = new ArrayList ();
  1058. _requiresPostBack.Add (control.UniqueID);
  1059. }
  1060. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1061. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  1062. {
  1063. requiresRaiseEvent = control;
  1064. }
  1065. #if NET_2_0
  1066. [Obsolete]
  1067. #endif
  1068. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1069. public virtual void RegisterStartupScript (string key, string script)
  1070. {
  1071. scriptManager.RegisterStartupScript (key, script);
  1072. }
  1073. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1074. public void RegisterViewStateHandler ()
  1075. {
  1076. handleViewState = true;
  1077. }
  1078. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1079. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  1080. {
  1081. _savedViewState = viewState;
  1082. }
  1083. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1084. protected virtual object LoadPageStateFromPersistenceMedium ()
  1085. {
  1086. NameValueCollection postdata = _requestValueCollection;
  1087. string view_state;
  1088. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  1089. return null;
  1090. _savedViewState = null;
  1091. if (view_state == "")
  1092. return null;
  1093. LosFormatter fmt = GetFormatter ();
  1094. try {
  1095. _savedViewState = fmt.Deserialize (view_state);
  1096. } catch (Exception e) {
  1097. throw new HttpException ("Error restoring page viewstate.", e);
  1098. }
  1099. return _savedViewState;
  1100. }
  1101. internal void LoadPageViewState()
  1102. {
  1103. object sState = LoadPageStateFromPersistenceMedium ();
  1104. if (sState != null) {
  1105. #if NET_2_0
  1106. Triplet data = (Triplet) sState;
  1107. if (allow_load) {
  1108. LoadPageControlState (data.Third);
  1109. LoadViewStateRecursive (data.First);
  1110. _requiresPostBack = data.Second as ArrayList;
  1111. }
  1112. #else
  1113. Pair pair = (Pair) sState;
  1114. if (allow_load) {
  1115. LoadViewStateRecursive (pair.First);
  1116. _requiresPostBack = pair.Second as ArrayList;
  1117. }
  1118. #endif
  1119. }
  1120. }
  1121. internal void SavePageViewState ()
  1122. {
  1123. if (!handleViewState)
  1124. return;
  1125. #if NET_2_0
  1126. object controlState = SavePageControlState ();
  1127. #endif
  1128. object viewState = SaveViewStateRecursive ();
  1129. object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
  1130. #if NET_2_0
  1131. Triplet triplet = new Triplet ();
  1132. triplet.First = viewState;
  1133. triplet.Second = reqPostback;
  1134. triplet.Third = controlState;
  1135. if (triplet.First == null && triplet.Second == null && triplet.Third == null)
  1136. triplet = null;
  1137. SavePageStateToPersistenceMedium (triplet);
  1138. #else
  1139. Pair pair = new Pair ();
  1140. pair.First = viewState;
  1141. pair.Second = reqPostback;
  1142. if (pair.First == null && pair.Second == null)
  1143. pair = null;
  1144. SavePageStateToPersistenceMedium (pair);
  1145. #endif
  1146. }
  1147. public virtual void Validate ()
  1148. {
  1149. is_validated = true;
  1150. ValidateCollection (_validators);
  1151. }
  1152. internal virtual bool AreValidatorsUplevel ()
  1153. {
  1154. bool uplevel = false;
  1155. foreach (IValidator v in Validators) {
  1156. BaseValidator bv = v as BaseValidator;
  1157. if (bv == null) continue;
  1158. if (bv.GetRenderUplevel()) {
  1159. uplevel = true;
  1160. break;
  1161. }
  1162. }
  1163. return uplevel;
  1164. }
  1165. bool ValidateCollection (ValidatorCollection validators)
  1166. {
  1167. #if NET_2_0
  1168. if (!_eventValidation)
  1169. return true;
  1170. #endif
  1171. if (validators == null || validators.Count == 0)
  1172. return true;
  1173. bool all_valid = true;
  1174. foreach (IValidator v in validators){
  1175. v.Validate ();
  1176. if (v.IsValid == false)
  1177. all_valid = false;
  1178. }
  1179. return all_valid;
  1180. }
  1181. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1182. public virtual void VerifyRenderingInServerForm (Control control)
  1183. {
  1184. if (_context == null)
  1185. return;
  1186. if (!renderingForm)
  1187. throw new HttpException ("Control '" +
  1188. control.ClientID +
  1189. "' of type '" +
  1190. control.GetType ().Name +
  1191. "' must be placed inside a form tag with runat=server.");
  1192. }
  1193. protected override void FrameworkInitialize ()
  1194. {
  1195. base.FrameworkInitialize ();
  1196. #if NET_2_0
  1197. InitializeStyleSheet ();
  1198. #endif
  1199. }
  1200. #endregion
  1201. #if NET_2_0
  1202. public
  1203. #else
  1204. internal
  1205. #endif
  1206. ClientScriptManager ClientScript {
  1207. get { return scriptManager; }
  1208. }
  1209. #if NET_2_0
  1210. static readonly object InitCompleteEvent = new object ();
  1211. static readonly object LoadCompleteEvent = new object ();
  1212. static readonly object PreInitEvent = new object ();
  1213. static readonly object PreLoadEvent = new object ();
  1214. static readonly object PreRenderCompleteEvent = new object ();
  1215. static readonly object SaveStateCompleteEvent = new object ();
  1216. int event_mask;
  1217. const int initcomplete_mask = 1;
  1218. const int loadcomplete_mask = 1 << 1;
  1219. const int preinit_mask = 1 << 2;
  1220. const int preload_mask = 1 << 3;
  1221. const int prerendercomplete_mask = 1 << 4;
  1222. const int savestatecomplete_mask = 1 << 5;
  1223. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1224. public event EventHandler InitComplete {
  1225. add {
  1226. event_mask |= initcomplete_mask;
  1227. Events.AddHandler (InitCompleteEvent, value);
  1228. }
  1229. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1230. }
  1231. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1232. public event EventHandler LoadComplete {
  1233. add {
  1234. event_mask |= loadcomplete_mask;
  1235. Events.AddHandler (LoadCompleteEvent, value);
  1236. }
  1237. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1238. }
  1239. public event EventHandler PreInit {
  1240. add {
  1241. event_mask |= preinit_mask;
  1242. Events.AddHandler (PreInitEvent, value);
  1243. }
  1244. remove { Events.RemoveHandler (PreInitEvent, value); }
  1245. }
  1246. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1247. public event EventHandler PreLoad {
  1248. add {
  1249. event_mask |= preload_mask;
  1250. Events.AddHandler (PreLoadEvent, value);
  1251. }
  1252. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1253. }
  1254. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1255. public event EventHandler PreRenderComplete {
  1256. add {
  1257. event_mask |= prerendercomplete_mask;
  1258. Events.AddHandler (PreRenderCompleteEvent, value);
  1259. }
  1260. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1261. }
  1262. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1263. public event EventHandler SaveStateComplete {
  1264. add {
  1265. event_mask |= savestatecomplete_mask;
  1266. Events.AddHandler (SaveStateCompleteEvent, value);
  1267. }
  1268. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1269. }
  1270. protected virtual void OnInitComplete (EventArgs e)
  1271. {
  1272. if ((event_mask & initcomplete_mask) != 0) {
  1273. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1274. if (eh != null) eh (this, e);
  1275. }
  1276. }
  1277. protected virtual void OnLoadComplete (EventArgs e)
  1278. {
  1279. if ((event_mask & loadcomplete_mask) != 0) {
  1280. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1281. if (eh != null) eh (this, e);
  1282. }
  1283. }
  1284. protected virtual void OnPreInit (EventArgs e)
  1285. {
  1286. if ((event_mask & preinit_mask) != 0) {
  1287. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1288. if (eh != null) eh (this, e);
  1289. }
  1290. }
  1291. protected virtual void OnPreLoad (EventArgs e)
  1292. {
  1293. if ((event_mask & preload_mask) != 0) {
  1294. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1295. if (eh != null) eh (this, e);
  1296. }
  1297. }
  1298. protected virtual void OnPreRenderComplete (EventArgs e)
  1299. {
  1300. if ((event_mask & prerendercomplete_mask) != 0) {
  1301. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1302. if (eh != null) eh (this, e);
  1303. }
  1304. }
  1305. protected virtual void OnSaveStateComplete (EventArgs e)
  1306. {
  1307. if ((event_mask & savestatecomplete_mask) != 0) {
  1308. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1309. if (eh != null) eh (this, e);
  1310. }
  1311. }
  1312. public HtmlForm Form {
  1313. get { return _form; }
  1314. }
  1315. internal void RegisterForm (HtmlForm form)
  1316. {
  1317. _form = form;
  1318. }
  1319. [BrowsableAttribute (false)]
  1320. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1321. public Page PreviousPage {
  1322. get { return previousPage; }
  1323. }
  1324. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1325. [BrowsableAttribute (false)]
  1326. public bool IsCallback {
  1327. get { return _requestValueCollection != null && _requestValueCollection [CallbackArgumentID] != null; }
  1328. }
  1329. [BrowsableAttribute (false)]
  1330. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1331. public bool IsCrossPagePostBack {
  1332. get { return _requestValueCollection != null && isCrossPagePostBack; }
  1333. }
  1334. string ProcessCallbackData ()
  1335. {
  1336. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1337. if (callbackTarget == null || callbackTarget.Length == 0)
  1338. throw new HttpException ("Callback target not provided.");
  1339. ICallbackEventHandler target = FindControl (callbackTarget) as ICallbackEventHandler;
  1340. if (target == null)
  1341. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1342. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1343. target.RaiseCallbackEvent (callbackArgument);
  1344. return target.GetCallbackResult ();
  1345. }
  1346. [BrowsableAttribute (false)]
  1347. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1348. public HtmlHead Header {
  1349. get { return htmlHeader; }
  1350. }
  1351. internal void SetHeader (HtmlHead header)
  1352. {
  1353. htmlHeader = header;
  1354. }
  1355. void ApplyMasterPage ()
  1356. {
  1357. if (masterPageFile != null) {
  1358. ArrayList appliedMasterPageFiles = new ArrayList ();
  1359. if (Master != null) {
  1360. MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
  1361. Master.Page = this;
  1362. Controls.Clear ();
  1363. Controls.Add (Master);
  1364. }
  1365. }
  1366. }
  1367. [DefaultValueAttribute ("")]
  1368. public virtual string MasterPageFile {
  1369. get { return masterPageFile; }
  1370. set {
  1371. masterPageFile = value;
  1372. masterPage = null;
  1373. }
  1374. }
  1375. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1376. [BrowsableAttribute (false)]
  1377. public MasterPage Master {
  1378. get {
  1379. if (masterPage == null)
  1380. masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
  1381. return masterPage;
  1382. }
  1383. }
  1384. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1385. public void RegisterRequiresControlState (Control control)
  1386. {
  1387. if (requireStateControls == null) requireStateControls = new ArrayList ();
  1388. requireStateControls.Add (control);
  1389. }
  1390. public bool RequiresControlState (Control control)
  1391. {
  1392. if (requireStateControls == null) return false;
  1393. return requireStateControls.Contains (control);
  1394. }
  1395. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1396. public void UnregisterRequiresControlState (Control control)
  1397. {
  1398. if (requireStateControls != null)
  1399. requireStateControls.Remove (control);
  1400. }
  1401. public ValidatorCollection GetValidators (string validationGroup)
  1402. {
  1403. if (validationGroup == null || validationGroup == "")
  1404. return Validators;
  1405. if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
  1406. ValidatorCollection col = _validatorsByGroup [validationGroup] as ValidatorCollection;
  1407. if (col == null) {
  1408. col = new ValidatorCollection ();
  1409. _validatorsByGroup [validationGroup] = col;
  1410. }
  1411. return col;
  1412. }
  1413. public virtual void Validate (string validationGroup)
  1414. {
  1415. is_validated = true;
  1416. if (validationGroup == null || validationGroup == "")
  1417. ValidateCollection (_validators);
  1418. else if (_validatorsByGroup != null) {
  1419. ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
  1420. }
  1421. }
  1422. object SavePageControlState ()
  1423. {
  1424. if (requireStateControls == null) return null;
  1425. object[] state = new object [requireStateControls.Count];
  1426. bool allNull = true;
  1427. for (int n=0; n<state.Length; n++) {
  1428. state [n] = ((Control) requireStateControls [n]).SaveControlState ();
  1429. if (state [n] != null) allNull = false;
  1430. }
  1431. if (allNull) return null;
  1432. else return state;
  1433. }
  1434. void LoadPageControlState (object data)
  1435. {
  1436. if (requireStateControls == null) return;
  1437. object[] state = (object[]) data;
  1438. int max = Math.Min (requireStateControls.Count, state != null ? state.Length : requireStateControls.Count);
  1439. for (int n=0; n < max; n++) {
  1440. Control ctl = (Control) requireStateControls [n];
  1441. ctl.LoadControlState (state != null ? state [n] : null);
  1442. }
  1443. }
  1444. void LoadPreviousPageReference ()
  1445. {
  1446. if (_requestValueCollection != null) {
  1447. string prevPage = _requestValueCollection [PreviousPageID];
  1448. if (prevPage != null) {
  1449. previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  1450. previousPage.ProcessCrossPagePostBack (_context);
  1451. } else {
  1452. previousPage = _context.LastPage;
  1453. }
  1454. }
  1455. _context.LastPage = this;
  1456. }
  1457. Hashtable contentTemplates;
  1458. [EditorBrowsable (EditorBrowsableState.Never)]
  1459. protected internal void AddContentTemplate (string templateName, ITemplate template)
  1460. {
  1461. if (contentTemplates == null)
  1462. contentTemplates = new Hashtable ();
  1463. contentTemplates [templateName] = template;
  1464. }
  1465. PageTheme _pageTheme;
  1466. internal PageTheme PageTheme {
  1467. get { return _pageTheme; }
  1468. }
  1469. PageTheme _styleSheetPageTheme;
  1470. internal PageTheme StyleSheetPageTheme {
  1471. get { return _styleSheetPageTheme; }
  1472. }
  1473. Stack dataItemCtx;
  1474. internal void PushDataItemContext (object o) {
  1475. if (dataItemCtx == null)
  1476. dataItemCtx = new Stack ();
  1477. dataItemCtx.Push (o);
  1478. }
  1479. internal void PopDataItemContext () {
  1480. if (dataItemCtx == null)
  1481. throw new InvalidOperationException ();
  1482. dataItemCtx.Pop ();
  1483. }
  1484. public object GetDataItem() {
  1485. if (dataItemCtx == null || dataItemCtx.Count == 0)
  1486. throw new InvalidOperationException ("No data item");
  1487. return dataItemCtx.Peek ();
  1488. }
  1489. #endif
  1490. }
  1491. }