Page.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  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. #if NET_2_0
  72. private PageLifeCycle _lifeCycle = PageLifeCycle.Unknown;
  73. private bool _eventValidation = true;
  74. private object [] _savedControlState;
  75. private bool _doLoadPreviousPage;
  76. string _focusedControlID;
  77. #endif
  78. private bool _viewState = true;
  79. private bool _viewStateMac;
  80. private string _errorPage;
  81. private bool is_validated;
  82. private bool _smartNavigation;
  83. private int _transactionMode;
  84. private HttpContext _context;
  85. private ValidatorCollection _validators;
  86. private bool renderingForm;
  87. private string _savedViewState;
  88. private ArrayList _requiresPostBack;
  89. private ArrayList _requiresPostBackCopy;
  90. private ArrayList requiresPostDataChanged;
  91. private IPostBackEventHandler requiresRaiseEvent;
  92. private NameValueCollection secondPostData;
  93. private bool requiresPostBackScript;
  94. private bool postBackScriptRendered;
  95. bool handleViewState;
  96. string viewStateUserKey;
  97. NameValueCollection _requestValueCollection;
  98. string clientTarget;
  99. ClientScriptManager scriptManager;
  100. bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
  101. PageStatePersister page_state_persister;
  102. [EditorBrowsable (EditorBrowsableState.Never)]
  103. #if NET_2_0
  104. public
  105. #else
  106. protected
  107. #endif
  108. const string postEventArgumentID = "__EVENTARGUMENT";
  109. [EditorBrowsable (EditorBrowsableState.Never)]
  110. #if NET_2_0
  111. public
  112. #else
  113. protected
  114. #endif
  115. const string postEventSourceID = "__EVENTTARGET";
  116. #if NET_2_0
  117. const string ScrollPositionXID = "__SCROLLPOSITIONX";
  118. const string ScrollPositionYID = "__SCROLLPOSITIONY";
  119. #endif
  120. #if NET_2_0
  121. internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
  122. internal const string CallbackSourceID = "__CALLBACKTARGET";
  123. internal const string PreviousPageID = "__PREVIOUSPAGE";
  124. HtmlHead htmlHeader;
  125. MasterPage masterPage;
  126. string masterPageFile;
  127. Page previousPage;
  128. bool isCrossPagePostBack;
  129. bool isPostBack;
  130. bool isCallback;
  131. ArrayList requireStateControls;
  132. Hashtable _validatorsByGroup;
  133. HtmlForm _form;
  134. string _title;
  135. string _theme;
  136. string _styleSheetTheme;
  137. Hashtable items;
  138. bool _maintainScrollPositionOnPostBack;
  139. #endif
  140. #region Constructor
  141. public Page ()
  142. {
  143. scriptManager = new ClientScriptManager (this);
  144. Page = this;
  145. ID = "__Page";
  146. }
  147. #endregion
  148. #region Properties
  149. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  150. [Browsable (false)]
  151. public HttpApplicationState Application
  152. {
  153. get {
  154. if (_context == null)
  155. return null;
  156. return _context.Application;
  157. }
  158. }
  159. [EditorBrowsable (EditorBrowsableState.Never)]
  160. protected bool AspCompatMode
  161. {
  162. #if NET_2_0
  163. get { return false; }
  164. #endif
  165. set { throw new NotImplementedException (); }
  166. }
  167. [EditorBrowsable (EditorBrowsableState.Never)]
  168. #if NET_2_0
  169. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  170. [BrowsableAttribute (false)]
  171. public bool Buffer
  172. {
  173. get { return Response.BufferOutput; }
  174. set { Response.BufferOutput = value; }
  175. }
  176. #else
  177. protected bool Buffer
  178. {
  179. set { Response.BufferOutput = value; }
  180. }
  181. #endif
  182. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  183. [Browsable (false)]
  184. public Cache Cache
  185. {
  186. get {
  187. if (_context == null)
  188. throw new HttpException ("No cache available without a context.");
  189. return _context.Cache;
  190. }
  191. }
  192. #if NET_2_0
  193. [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
  194. #endif
  195. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  196. [Browsable (false), DefaultValue ("")]
  197. [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
  198. public string ClientTarget
  199. {
  200. get { return (clientTarget == null) ? "" : clientTarget; }
  201. set {
  202. clientTarget = value;
  203. if (value == "")
  204. clientTarget = null;
  205. }
  206. }
  207. [EditorBrowsable (EditorBrowsableState.Never)]
  208. #if NET_2_0
  209. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  210. [BrowsableAttribute (false)]
  211. public int CodePage
  212. {
  213. get { return Response.ContentEncoding.CodePage; }
  214. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  215. }
  216. #else
  217. protected int CodePage
  218. {
  219. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  220. }
  221. #endif
  222. [EditorBrowsable (EditorBrowsableState.Never)]
  223. #if NET_2_0
  224. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  225. [BrowsableAttribute (false)]
  226. public string ContentType
  227. {
  228. get { return Response.ContentType; }
  229. set { Response.ContentType = value; }
  230. }
  231. #else
  232. protected string ContentType
  233. {
  234. set { Response.ContentType = value; }
  235. }
  236. #endif
  237. protected override HttpContext Context
  238. {
  239. get {
  240. if (_context == null)
  241. return HttpContext.Current;
  242. return _context;
  243. }
  244. }
  245. #if NET_2_0
  246. [EditorBrowsable (EditorBrowsableState.Advanced)]
  247. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  248. [BrowsableAttribute (false)]
  249. public string Culture
  250. {
  251. get { return Thread.CurrentThread.CurrentCulture.Name; }
  252. set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
  253. }
  254. #else
  255. [EditorBrowsable (EditorBrowsableState.Never)]
  256. protected string Culture
  257. {
  258. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  259. }
  260. #endif
  261. #if NET_2_0
  262. public virtual bool EnableEventValidation {
  263. get { return _eventValidation; }
  264. set {
  265. if (_lifeCycle > PageLifeCycle.Init)
  266. throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
  267. _eventValidation = value;
  268. }
  269. }
  270. internal PageLifeCycle LifeCycle {
  271. get { return _lifeCycle; }
  272. }
  273. #endif
  274. [Browsable (false)]
  275. public override bool EnableViewState
  276. {
  277. get { return _viewState; }
  278. set { _viewState = value; }
  279. }
  280. #if NET_2_0
  281. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  282. [BrowsableAttribute (false)]
  283. #endif
  284. [EditorBrowsable (EditorBrowsableState.Never)]
  285. #if NET_2_0
  286. public
  287. #else
  288. protected
  289. #endif
  290. bool EnableViewStateMac
  291. {
  292. get { return _viewStateMac; }
  293. set { _viewStateMac = value; }
  294. }
  295. #if NET_1_1
  296. internal bool EnableViewStateMacInternal {
  297. get { return _viewStateMac; }
  298. set { _viewStateMac = value; }
  299. }
  300. #endif
  301. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  302. [Browsable (false), DefaultValue ("")]
  303. [WebSysDescription ("The URL of a page used for error redirection.")]
  304. public string ErrorPage
  305. {
  306. get { return _errorPage; }
  307. set {
  308. _errorPage = value;
  309. if (_context != null)
  310. _context.ErrorPage = value;
  311. }
  312. }
  313. #if NET_2_0
  314. [Obsolete]
  315. #endif
  316. [EditorBrowsable (EditorBrowsableState.Never)]
  317. protected ArrayList FileDependencies
  318. {
  319. set {
  320. if (Response != null)
  321. Response.AddFileDependencies (value);
  322. }
  323. }
  324. [Browsable (false)]
  325. #if NET_2_0
  326. [EditorBrowsable (EditorBrowsableState.Never)]
  327. #endif
  328. public override string ID
  329. {
  330. get { return base.ID; }
  331. set { base.ID = value; }
  332. }
  333. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  334. [Browsable (false)]
  335. public bool IsPostBack
  336. {
  337. get {
  338. #if NET_2_0
  339. return isPostBack;
  340. #else
  341. return _requestValueCollection != null;
  342. #endif
  343. }
  344. }
  345. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  346. public bool IsReusable {
  347. get { return false; }
  348. }
  349. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  350. [Browsable (false)]
  351. public bool IsValid {
  352. get {
  353. if (!is_validated)
  354. throw new HttpException (Locale.GetText ("Page hasn't been validated."));
  355. #if NET_2_0
  356. foreach (IValidator val in Validators)
  357. if (!val.IsValid)
  358. return false;
  359. return true;
  360. #else
  361. return ValidateCollection (_validators);
  362. #endif
  363. }
  364. }
  365. #if NET_2_0
  366. public IDictionary Items {
  367. get {
  368. if (items == null)
  369. items = new Hashtable ();
  370. return items;
  371. }
  372. }
  373. #endif
  374. [EditorBrowsable (EditorBrowsableState.Never)]
  375. #if NET_2_0
  376. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  377. [BrowsableAttribute (false)]
  378. public int LCID {
  379. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  380. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  381. }
  382. #else
  383. protected int LCID {
  384. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  385. }
  386. #endif
  387. #if NET_2_0
  388. [Browsable (false)]
  389. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  390. public bool MaintainScrollPositionOnPostBack {
  391. get { return _maintainScrollPositionOnPostBack; }
  392. set { _maintainScrollPositionOnPostBack = value; }
  393. }
  394. #endif
  395. #if NET_2_0
  396. public PageAdapter PageAdapter {
  397. get {
  398. return (PageAdapter)Adapter;
  399. }
  400. }
  401. #endif
  402. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  403. [Browsable (false)]
  404. public HttpRequest Request
  405. {
  406. get {
  407. if (_context != null)
  408. return _context.Request;
  409. throw new HttpException("Request is not available without context");
  410. }
  411. }
  412. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  413. [Browsable (false)]
  414. public HttpResponse Response
  415. {
  416. get {
  417. if (_context != null)
  418. return _context.Response;
  419. throw new HttpException ("Response is not available without context");
  420. }
  421. }
  422. [EditorBrowsable (EditorBrowsableState.Never)]
  423. #if NET_2_0
  424. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  425. [BrowsableAttribute (false)]
  426. public string ResponseEncoding
  427. {
  428. get { return Response.ContentEncoding.WebName; }
  429. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  430. }
  431. #else
  432. protected string ResponseEncoding
  433. {
  434. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  435. }
  436. #endif
  437. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  438. [Browsable (false)]
  439. public HttpServerUtility Server
  440. {
  441. get {
  442. return Context.Server;
  443. }
  444. }
  445. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  446. [Browsable (false)]
  447. public virtual HttpSessionState Session
  448. {
  449. get {
  450. if (_context == null)
  451. _context = HttpContext.Current;
  452. if (_context == null)
  453. throw new HttpException ("Session is not available without context");
  454. if (_context.Session == null)
  455. throw new HttpException ("Session state can only be used " +
  456. "when enableSessionState is set to true, either " +
  457. "in a configuration file or in the Page directive.");
  458. return _context.Session;
  459. }
  460. }
  461. #if NET_2_0
  462. [FilterableAttribute (false)]
  463. [Obsolete]
  464. #endif
  465. [Browsable (false)]
  466. public bool SmartNavigation
  467. {
  468. get { return _smartNavigation; }
  469. set { _smartNavigation = value; }
  470. }
  471. #if NET_2_0
  472. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  473. [Filterable (false)]
  474. [Browsable (false)]
  475. public virtual string StyleSheetTheme {
  476. get { return _styleSheetTheme; }
  477. set { _styleSheetTheme = value; }
  478. }
  479. [Browsable (false)]
  480. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  481. public virtual string Theme {
  482. get { return _theme; }
  483. set { _theme = value; }
  484. }
  485. void InitializeStyleSheet ()
  486. {
  487. if (_styleSheetTheme == null) {
  488. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  489. if (ps != null)
  490. _styleSheetTheme = ps.StyleSheetTheme;
  491. }
  492. if (_styleSheetTheme != null && _styleSheetTheme != "")
  493. _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, _context);
  494. }
  495. void InitializeTheme ()
  496. {
  497. if (_theme == null) {
  498. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  499. if (ps != null)
  500. _theme = ps.Theme;
  501. }
  502. if (_theme != null && _theme != "") {
  503. _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, _context);
  504. }
  505. }
  506. #endif
  507. #if NET_2_0
  508. [Localizable (true)]
  509. [Bindable (true)]
  510. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  511. public string Title {
  512. get {
  513. if (_title == null)
  514. return htmlHeader.Title;
  515. return _title;
  516. }
  517. set {
  518. if (htmlHeader != null)
  519. htmlHeader.Title = value;
  520. else
  521. _title = value;
  522. }
  523. }
  524. #endif
  525. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  526. [Browsable (false)]
  527. public TraceContext Trace
  528. {
  529. get { return Context.Trace; }
  530. }
  531. [EditorBrowsable (EditorBrowsableState.Never)]
  532. #if NET_2_0
  533. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  534. [BrowsableAttribute (false)]
  535. public bool TraceEnabled
  536. {
  537. get { return Trace.IsEnabled; }
  538. set { Trace.IsEnabled = value; }
  539. }
  540. #else
  541. protected bool TraceEnabled
  542. {
  543. set { Trace.IsEnabled = value; }
  544. }
  545. #endif
  546. [EditorBrowsable (EditorBrowsableState.Never)]
  547. #if NET_2_0
  548. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  549. [BrowsableAttribute (false)]
  550. public TraceMode TraceModeValue
  551. {
  552. get { return Trace.TraceMode; }
  553. set { Trace.TraceMode = value; }
  554. }
  555. #else
  556. protected TraceMode TraceModeValue
  557. {
  558. set { Trace.TraceMode = value; }
  559. }
  560. #endif
  561. [EditorBrowsable (EditorBrowsableState.Never)]
  562. protected int TransactionMode
  563. {
  564. #if NET_2_0
  565. get { return _transactionMode; }
  566. #endif
  567. set { _transactionMode = value; }
  568. }
  569. #if NET_2_0
  570. [EditorBrowsable (EditorBrowsableState.Advanced)]
  571. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  572. [BrowsableAttribute (false)]
  573. public string UICulture
  574. {
  575. get { return Thread.CurrentThread.CurrentUICulture.Name; }
  576. set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
  577. }
  578. #else
  579. [EditorBrowsable (EditorBrowsableState.Never)]
  580. protected string UICulture
  581. {
  582. set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
  583. }
  584. #endif
  585. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  586. [Browsable (false)]
  587. public IPrincipal User
  588. {
  589. get { return Context.User; }
  590. }
  591. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  592. [Browsable (false)]
  593. public ValidatorCollection Validators
  594. {
  595. get {
  596. if (_validators == null)
  597. _validators = new ValidatorCollection ();
  598. return _validators;
  599. }
  600. }
  601. [MonoTODO ("Use this when encrypting/decrypting ViewState")]
  602. [Browsable (false)]
  603. public string ViewStateUserKey {
  604. get { return viewStateUserKey; }
  605. set { viewStateUserKey = value; }
  606. }
  607. [Browsable (false)]
  608. public override bool Visible
  609. {
  610. get { return base.Visible; }
  611. set { base.Visible = value; }
  612. }
  613. #endregion
  614. #region Methods
  615. #if NET_2_0
  616. CultureInfo GetPageCulture (string culture, CultureInfo deflt)
  617. {
  618. if (culture == null)
  619. return deflt;
  620. CultureInfo ret = null;
  621. if (culture.StartsWith ("auto")) {
  622. string[] languages = Request.UserLanguages;
  623. try {
  624. if (languages != null && languages.Length > 0)
  625. ret = new CultureInfo (languages[0]);
  626. } catch {
  627. }
  628. if (ret == null)
  629. ret = deflt;
  630. } else
  631. ret = new CultureInfo (culture);
  632. return ret;
  633. }
  634. #endif
  635. [EditorBrowsable (EditorBrowsableState.Never)]
  636. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  637. AsyncCallback cb,
  638. object extraData)
  639. {
  640. throw new NotImplementedException ();
  641. }
  642. [EditorBrowsable (EditorBrowsableState.Never)]
  643. protected void AspCompatEndProcessRequest (IAsyncResult result)
  644. {
  645. throw new NotImplementedException ();
  646. }
  647. [EditorBrowsable (EditorBrowsableState.Advanced)]
  648. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  649. {
  650. return new HtmlTextWriter (tw);
  651. }
  652. [EditorBrowsable (EditorBrowsableState.Never)]
  653. public void DesignerInitialize ()
  654. {
  655. InitRecursive (null);
  656. }
  657. [EditorBrowsable (EditorBrowsableState.Advanced)]
  658. protected virtual NameValueCollection DeterminePostBackMode ()
  659. {
  660. if (_context == null)
  661. return null;
  662. HttpRequest req = _context.Request;
  663. if (req == null)
  664. return null;
  665. NameValueCollection coll = null;
  666. if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
  667. coll = req.Form;
  668. WebROCollection c = (WebROCollection) coll;
  669. allow_load = !c.GotID;
  670. if (allow_load) {
  671. c.ID = GetTypeHashCode ();
  672. } else {
  673. allow_load = (c.ID == GetTypeHashCode ());
  674. }
  675. } else {
  676. coll = req.QueryString;
  677. }
  678. if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
  679. return null;
  680. return coll;
  681. }
  682. #if NET_2_0
  683. public override Control FindControl (string id) {
  684. if (id == ID)
  685. return this;
  686. else
  687. return base.FindControl (id);
  688. }
  689. #endif
  690. #if NET_2_0
  691. [Obsolete]
  692. #endif
  693. [EditorBrowsable (EditorBrowsableState.Advanced)]
  694. public string GetPostBackClientEvent (Control control, string argument)
  695. {
  696. return scriptManager.GetPostBackEventReference (control, argument);
  697. }
  698. #if NET_2_0
  699. [Obsolete]
  700. #endif
  701. [EditorBrowsable (EditorBrowsableState.Advanced)]
  702. public string GetPostBackClientHyperlink (Control control, string argument)
  703. {
  704. return scriptManager.GetPostBackClientHyperlink (control, argument);
  705. }
  706. #if NET_2_0
  707. [Obsolete]
  708. #endif
  709. [EditorBrowsable (EditorBrowsableState.Advanced)]
  710. public string GetPostBackEventReference (Control control)
  711. {
  712. return scriptManager.GetPostBackEventReference (control, "");
  713. }
  714. #if NET_2_0
  715. [Obsolete]
  716. #endif
  717. [EditorBrowsable (EditorBrowsableState.Advanced)]
  718. public string GetPostBackEventReference (Control control, string argument)
  719. {
  720. return scriptManager.GetPostBackEventReference (control, argument);
  721. }
  722. internal void RequiresPostBackScript ()
  723. {
  724. requiresPostBackScript = true;
  725. }
  726. [EditorBrowsable (EditorBrowsableState.Never)]
  727. public virtual int GetTypeHashCode ()
  728. {
  729. return 0;
  730. }
  731. #if NET_2_0
  732. [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
  733. protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
  734. {
  735. if (cacheSettings.Enabled)
  736. InitOutputCache(cacheSettings.Duration,
  737. cacheSettings.VaryByHeader,
  738. cacheSettings.VaryByCustom,
  739. cacheSettings.Location,
  740. cacheSettings.VaryByParam);
  741. }
  742. #endif
  743. [EditorBrowsable (EditorBrowsableState.Never)]
  744. protected virtual void InitOutputCache (int duration,
  745. string varyByHeader,
  746. string varyByCustom,
  747. OutputCacheLocation location,
  748. string varyByParam)
  749. {
  750. HttpCachePolicy cache = _context.Response.Cache;
  751. bool set_vary = false;
  752. switch (location) {
  753. case OutputCacheLocation.Any:
  754. cache.SetCacheability (HttpCacheability.Public);
  755. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  756. cache.SetLastModified (_context.Timestamp);
  757. set_vary = true;
  758. break;
  759. case OutputCacheLocation.Client:
  760. cache.SetCacheability (HttpCacheability.Private);
  761. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  762. cache.SetLastModified (_context.Timestamp);
  763. break;
  764. case OutputCacheLocation.Downstream:
  765. cache.SetCacheability (HttpCacheability.Public);
  766. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  767. cache.SetLastModified (_context.Timestamp);
  768. break;
  769. case OutputCacheLocation.Server:
  770. cache.SetCacheability (HttpCacheability.Server);
  771. set_vary = true;
  772. break;
  773. case OutputCacheLocation.None:
  774. break;
  775. }
  776. if (set_vary) {
  777. if (varyByCustom != null)
  778. cache.SetVaryByCustom (varyByCustom);
  779. if (varyByParam != null && varyByParam.Length > 0) {
  780. string[] prms = varyByParam.Split (';');
  781. foreach (string p in prms)
  782. cache.VaryByParams [p.Trim ()] = true;
  783. cache.VaryByParams.IgnoreParams = false;
  784. } else {
  785. cache.VaryByParams.IgnoreParams = true;
  786. }
  787. if (varyByHeader != null && varyByHeader.Length > 0) {
  788. string[] hdrs = varyByHeader.Split (';');
  789. foreach (string h in hdrs)
  790. cache.VaryByHeaders [h.Trim ()] = true;
  791. }
  792. }
  793. cache.Duration = duration;
  794. cache.SetExpires (_context.Timestamp.AddSeconds (duration));
  795. }
  796. #if NET_2_0
  797. [Obsolete]
  798. #else
  799. [EditorBrowsable (EditorBrowsableState.Advanced)]
  800. #endif
  801. public bool IsClientScriptBlockRegistered (string key)
  802. {
  803. return scriptManager.IsClientScriptBlockRegistered (key);
  804. }
  805. #if NET_2_0
  806. [Obsolete]
  807. #else
  808. [EditorBrowsable (EditorBrowsableState.Advanced)]
  809. #endif
  810. public bool IsStartupScriptRegistered (string key)
  811. {
  812. return scriptManager.IsStartupScriptRegistered (key);
  813. }
  814. public string MapPath (string virtualPath)
  815. {
  816. return Request.MapPath (virtualPath);
  817. }
  818. #if NET_2_0
  819. protected internal override void Render (HtmlTextWriter writer) {
  820. if (MaintainScrollPositionOnPostBack) {
  821. RequiresPostBackScript ();
  822. string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
  823. ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
  824. ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
  825. ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
  826. StringBuilder script = new StringBuilder ();
  827. script.AppendLine ("<script type=\"text/javascript\">");
  828. script.AppendLine ("<!--");
  829. script.AppendLine ("theForm.oldSubmit = theForm.submit");
  830. script.AppendLine ("theForm.submit = WebForm_SaveScrollPositionSubmit");
  831. script.AppendLine ("theForm.oldOnSubmit = theForm.onsubmit");
  832. script.AppendLine ("theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit");
  833. if (IsPostBack) {
  834. script.AppendLine ("theForm.oldOnLoad = window.onload");
  835. script.AppendLine ("window.onload = WebForm_RestoreScrollPosition");
  836. }
  837. script.AppendLine ("// -->");
  838. script.AppendLine ("</script>");
  839. ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
  840. }
  841. base.Render (writer);
  842. }
  843. #endif
  844. private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  845. {
  846. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
  847. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
  848. writer.WriteLine ();
  849. writer.WriteLine ("<script language=\"javascript\">");
  850. writer.WriteLine ("<!--");
  851. writer.WriteLine ("\tvar theForm;\n\tif (document.getElementById) {{ theForm = document.getElementById ('{0}'); }}", formUniqueID);
  852. writer.WriteLine ("\telse {{ theForm = document.{0}; }}", formUniqueID);
  853. writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
  854. writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
  855. writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
  856. writer.WriteLine ("\t\ttheForm.submit();");
  857. writer.WriteLine ("\t}");
  858. writer.WriteLine ("// -->");
  859. writer.WriteLine ("</script>");
  860. }
  861. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  862. {
  863. if (renderingForm)
  864. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  865. renderingForm = true;
  866. writer.WriteLine ();
  867. scriptManager.WriteHiddenFields (writer);
  868. if (requiresPostBackScript) {
  869. RenderPostBackScript (writer, formUniqueID);
  870. postBackScriptRendered = true;
  871. }
  872. if (handleViewState)
  873. writer.WriteLine ("<input type=\"hidden\" name=\"__VIEWSTATE\" value=\"{0}\" />", _savedViewState);
  874. scriptManager.WriteClientScriptBlocks (writer);
  875. }
  876. internal IStateFormatter GetFormatter ()
  877. {
  878. return new ObjectStateFormatter (this);
  879. }
  880. internal object GetSavedViewState ()
  881. {
  882. return _savedViewState;
  883. }
  884. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  885. {
  886. scriptManager.WriteArrayDeclares (writer);
  887. if (!postBackScriptRendered && requiresPostBackScript)
  888. RenderPostBackScript (writer, formUniqueID);
  889. #if NET_2_0
  890. scriptManager.SaveEventValidationState ();
  891. scriptManager.WriteExpandoAttributes (writer);
  892. #endif
  893. scriptManager.WriteHiddenFields (writer);
  894. scriptManager.WriteClientScriptIncludes (writer);
  895. scriptManager.WriteStartupScriptBlocks (writer);
  896. renderingForm = false;
  897. postBackScriptRendered = false;
  898. }
  899. private void ProcessPostData (NameValueCollection data, bool second)
  900. {
  901. if (data != null) {
  902. Hashtable used = new Hashtable ();
  903. foreach (string id in data.AllKeys){
  904. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
  905. continue;
  906. string real_id = id;
  907. int dot = real_id.IndexOf ('.');
  908. if (dot >= 1)
  909. real_id = real_id.Substring (0, dot);
  910. if (real_id == null || used.ContainsKey (real_id))
  911. continue;
  912. used.Add (real_id, real_id);
  913. Control ctrl = FindControl (real_id);
  914. if (ctrl != null){
  915. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  916. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  917. if (pbdh == null) {
  918. if (pbeh != null)
  919. RegisterRequiresRaiseEvent (pbeh);
  920. continue;
  921. }
  922. if (pbdh.LoadPostData (real_id, data) == true) {
  923. if (requiresPostDataChanged == null)
  924. requiresPostDataChanged = new ArrayList ();
  925. requiresPostDataChanged.Add (pbdh);
  926. }
  927. if (_requiresPostBackCopy != null)
  928. _requiresPostBackCopy.Remove (real_id);
  929. } else if (!second) {
  930. if (secondPostData == null)
  931. secondPostData = new NameValueCollection ();
  932. secondPostData.Add (real_id, data [id]);
  933. }
  934. }
  935. }
  936. ArrayList list1 = null;
  937. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  938. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  939. foreach (string id in handlers) {
  940. IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
  941. if (pbdh != null) {
  942. _requiresPostBackCopy.Remove (id);
  943. if (pbdh.LoadPostData (id, data)) {
  944. if (requiresPostDataChanged == null)
  945. requiresPostDataChanged = new ArrayList ();
  946. requiresPostDataChanged.Add (pbdh);
  947. }
  948. } else if (!second) {
  949. if (list1 == null)
  950. list1 = new ArrayList ();
  951. list1.Add (id);
  952. }
  953. }
  954. }
  955. _requiresPostBackCopy = second ? null : list1;
  956. if (second)
  957. secondPostData = null;
  958. }
  959. [EditorBrowsable (EditorBrowsableState.Never)]
  960. #if NET_2_0 || TARGET_JVM
  961. public virtual void ProcessRequest (HttpContext context)
  962. #else
  963. public void ProcessRequest (HttpContext context)
  964. #endif
  965. {
  966. #if NET_2_0
  967. _lifeCycle = PageLifeCycle.Unknown;
  968. #endif
  969. _context = context;
  970. if (clientTarget != null)
  971. Request.ClientTarget = clientTarget;
  972. WireupAutomaticEvents ();
  973. //-- Control execution lifecycle in the docs
  974. // Save culture information because it can be modified in FrameworkInitialize()
  975. CultureInfo culture = Thread.CurrentThread.CurrentCulture;
  976. CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
  977. FrameworkInitialize ();
  978. context.ErrorPage = _errorPage;
  979. try {
  980. InternalProcessRequest ();
  981. } catch (ThreadAbortException) {
  982. // Do nothing, just ignore it by now.
  983. } catch (Exception e) {
  984. context.AddError (e); // OnError might access LastError
  985. OnError (EventArgs.Empty);
  986. context.ClearError (e);
  987. // We want to remove that error, as we're rethrowing to stop
  988. // further processing.
  989. Trace.Warn ("Unhandled Exception", e.ToString (), e);
  990. throw;
  991. } finally {
  992. try {
  993. #if NET_2_0
  994. _lifeCycle = PageLifeCycle.Unload;
  995. #endif
  996. RenderTrace ();
  997. UnloadRecursive (true);
  998. #if NET_2_0
  999. _lifeCycle = PageLifeCycle.End;
  1000. #endif
  1001. } catch {}
  1002. if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
  1003. Thread.CurrentThread.CurrentCulture = culture;
  1004. if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
  1005. Thread.CurrentThread.CurrentUICulture = uiculture;
  1006. }
  1007. }
  1008. #if NET_2_0
  1009. internal void ProcessCrossPagePostBack (HttpContext context)
  1010. {
  1011. isCrossPagePostBack = true;
  1012. ProcessRequest (context);
  1013. }
  1014. #endif
  1015. void InternalProcessRequest ()
  1016. {
  1017. _requestValueCollection = this.DeterminePostBackMode();
  1018. #if NET_2_0
  1019. _lifeCycle = PageLifeCycle.Start;
  1020. // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
  1021. if (_requestValueCollection != null) {
  1022. if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
  1023. _doLoadPreviousPage = true;
  1024. }
  1025. else {
  1026. isCallback = _requestValueCollection [CallbackArgumentID] != null;
  1027. isPostBack = !isCallback;
  1028. }
  1029. }
  1030. // if request was transfered from other page - track Prev. Page
  1031. previousPage = _context.LastPage;
  1032. _context.LastPage = this;
  1033. InitializeCulture ();
  1034. _lifeCycle = PageLifeCycle.PreInit;
  1035. OnPreInit (EventArgs.Empty);
  1036. InitializeTheme ();
  1037. ApplyMasterPage ();
  1038. _lifeCycle = PageLifeCycle.Init;
  1039. #endif
  1040. Trace.Write ("aspx.page", "Begin Init");
  1041. InitRecursive (null);
  1042. Trace.Write ("aspx.page", "End Init");
  1043. #if NET_2_0
  1044. _lifeCycle = PageLifeCycle.InitComplete;
  1045. OnInitComplete (EventArgs.Empty);
  1046. #endif
  1047. renderingForm = false;
  1048. #if NET_2_0
  1049. if (IsPostBack || IsCallback) {
  1050. _lifeCycle = PageLifeCycle.PreLoad;
  1051. if (_requestValueCollection != null)
  1052. scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
  1053. #else
  1054. if (IsPostBack) {
  1055. #endif
  1056. Trace.Write ("aspx.page", "Begin LoadViewState");
  1057. LoadPageViewState ();
  1058. Trace.Write ("aspx.page", "End LoadViewState");
  1059. Trace.Write ("aspx.page", "Begin ProcessPostData");
  1060. ProcessPostData (_requestValueCollection, false);
  1061. Trace.Write ("aspx.page", "End ProcessPostData");
  1062. }
  1063. #if NET_2_0
  1064. OnPreLoad (EventArgs.Empty);
  1065. _lifeCycle = PageLifeCycle.Load;
  1066. #endif
  1067. LoadRecursive ();
  1068. #if NET_2_0
  1069. if (IsPostBack || IsCallback) {
  1070. _lifeCycle = PageLifeCycle.ControlEvents;
  1071. #else
  1072. if (IsPostBack) {
  1073. #endif
  1074. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  1075. ProcessPostData (secondPostData, true);
  1076. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  1077. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  1078. RaiseChangedEvents ();
  1079. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  1080. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  1081. RaisePostBackEvents ();
  1082. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  1083. }
  1084. #if NET_2_0
  1085. _lifeCycle = PageLifeCycle.LoadComplete;
  1086. OnLoadComplete (EventArgs.Empty);
  1087. if (IsCrossPagePostBack)
  1088. return;
  1089. if (IsCallback) {
  1090. string result = ProcessCallbackData ();
  1091. HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
  1092. callbackOutput.Write (result);
  1093. callbackOutput.Flush ();
  1094. return;
  1095. }
  1096. _lifeCycle = PageLifeCycle.PreRender;
  1097. #endif
  1098. Trace.Write ("aspx.page", "Begin PreRender");
  1099. PreRenderRecursiveInternal ();
  1100. Trace.Write ("aspx.page", "End PreRender");
  1101. #if NET_2_0
  1102. _lifeCycle = PageLifeCycle.PreRenderComplete;
  1103. OnPreRenderComplete (EventArgs.Empty);
  1104. #endif
  1105. Trace.Write ("aspx.page", "Begin SaveViewState");
  1106. SavePageViewState ();
  1107. Trace.Write ("aspx.page", "End SaveViewState");
  1108. #if NET_2_0
  1109. _lifeCycle = PageLifeCycle.SaveStateComplete;
  1110. OnSaveStateComplete (EventArgs.Empty);
  1111. _lifeCycle = PageLifeCycle.Render;
  1112. #endif
  1113. //--
  1114. Trace.Write ("aspx.page", "Begin Render");
  1115. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1116. RenderControl (output);
  1117. Trace.Write ("aspx.page", "End Render");
  1118. }
  1119. private void RenderTrace ()
  1120. {
  1121. TraceManager traceManager = HttpRuntime.TraceManager;
  1122. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  1123. return;
  1124. Trace.SaveData ();
  1125. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  1126. return;
  1127. if (!traceManager.LocalOnly || Context.Request.IsLocal) {
  1128. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1129. Trace.Render (output);
  1130. }
  1131. }
  1132. #if NET_2_0
  1133. bool CheckForValidationSupport (Control targetControl)
  1134. {
  1135. if (targetControl == null)
  1136. return false;
  1137. Type type = targetControl.GetType ();
  1138. object[] attributes = type.GetCustomAttributes (true);
  1139. foreach (object attr in attributes)
  1140. if (attr is SupportsEventValidationAttribute)
  1141. return true;
  1142. return false;
  1143. }
  1144. #endif
  1145. void RaisePostBackEvents ()
  1146. {
  1147. #if NET_2_0
  1148. Control targetControl;
  1149. #endif
  1150. if (requiresRaiseEvent != null) {
  1151. #if NET_2_0
  1152. targetControl = requiresRaiseEvent as Control;
  1153. if (targetControl != null && CheckForValidationSupport (targetControl))
  1154. scriptManager.ValidateEvent (targetControl.UniqueID, null);
  1155. #endif
  1156. RaisePostBackEvent (requiresRaiseEvent, null);
  1157. return;
  1158. }
  1159. NameValueCollection postdata = _requestValueCollection;
  1160. if (postdata == null)
  1161. return;
  1162. string eventTarget = postdata [postEventSourceID];
  1163. if (eventTarget == null || eventTarget.Length == 0) {
  1164. Validate ();
  1165. return;
  1166. }
  1167. #if NET_2_0
  1168. targetControl = FindControl (eventTarget);
  1169. IPostBackEventHandler target = targetControl as IPostBackEventHandler;
  1170. #else
  1171. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  1172. #endif
  1173. if (target == null)
  1174. return;
  1175. string eventArgument = postdata [postEventArgumentID];
  1176. #if NET_2_0
  1177. if (CheckForValidationSupport (targetControl))
  1178. scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
  1179. #endif
  1180. RaisePostBackEvent (target, eventArgument);
  1181. }
  1182. internal void RaiseChangedEvents ()
  1183. {
  1184. if (requiresPostDataChanged == null)
  1185. return;
  1186. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1187. ipdh.RaisePostDataChangedEvent ();
  1188. requiresPostDataChanged = null;
  1189. }
  1190. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1191. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1192. {
  1193. sourceControl.RaisePostBackEvent (eventArgument);
  1194. }
  1195. #if NET_2_0
  1196. [Obsolete]
  1197. #endif
  1198. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1199. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1200. {
  1201. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1202. }
  1203. #if NET_2_0
  1204. [Obsolete]
  1205. #endif
  1206. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1207. public virtual void RegisterClientScriptBlock (string key, string script)
  1208. {
  1209. scriptManager.RegisterClientScriptBlock (key, script);
  1210. }
  1211. #if NET_2_0
  1212. [Obsolete]
  1213. #endif
  1214. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1215. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1216. {
  1217. scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  1218. }
  1219. [MonoTODO("Not implemented, Used in HtmlForm")]
  1220. internal void RegisterClientScriptFile (string a, string b, string c)
  1221. {
  1222. throw new NotImplementedException ();
  1223. }
  1224. #if NET_2_0
  1225. [Obsolete]
  1226. #endif
  1227. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1228. public void RegisterOnSubmitStatement (string key, string script)
  1229. {
  1230. scriptManager.RegisterOnSubmitStatement (key, script);
  1231. }
  1232. internal string GetSubmitStatements ()
  1233. {
  1234. return scriptManager.WriteSubmitStatements ();
  1235. }
  1236. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1237. public void RegisterRequiresPostBack (Control control)
  1238. {
  1239. if (_requiresPostBack == null)
  1240. _requiresPostBack = new ArrayList ();
  1241. if (_requiresPostBack.Contains (control.UniqueID))
  1242. return;
  1243. _requiresPostBack.Add (control.UniqueID);
  1244. }
  1245. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1246. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  1247. {
  1248. requiresRaiseEvent = control;
  1249. }
  1250. #if NET_2_0
  1251. [Obsolete]
  1252. #endif
  1253. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1254. public virtual void RegisterStartupScript (string key, string script)
  1255. {
  1256. scriptManager.RegisterStartupScript (key, script);
  1257. }
  1258. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1259. public void RegisterViewStateHandler ()
  1260. {
  1261. handleViewState = true;
  1262. }
  1263. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1264. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  1265. {
  1266. PageStatePersister persister = this.PageStatePersister;
  1267. if (persister == null)
  1268. return;
  1269. Pair pair = viewState as Pair;
  1270. if (pair != null) {
  1271. persister.ViewState = pair.First;
  1272. persister.ControlState = pair.Second;
  1273. } else
  1274. persister.ViewState = viewState;
  1275. persister.Save ();
  1276. }
  1277. internal string RawViewState {
  1278. get {
  1279. NameValueCollection postdata = _requestValueCollection;
  1280. string view_state;
  1281. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  1282. return null;
  1283. if (view_state == "")
  1284. return null;
  1285. return view_state;
  1286. }
  1287. set { _savedViewState = value; }
  1288. }
  1289. #if NET_2_0
  1290. protected virtual
  1291. #else
  1292. internal
  1293. #endif
  1294. PageStatePersister PageStatePersister {
  1295. get {
  1296. if (page_state_persister == null)
  1297. page_state_persister = new HiddenFieldPageStatePersister (this);
  1298. return page_state_persister;
  1299. }
  1300. }
  1301. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1302. protected virtual object LoadPageStateFromPersistenceMedium ()
  1303. {
  1304. PageStatePersister persister = this.PageStatePersister;
  1305. if (persister == null)
  1306. return null;
  1307. persister.Load ();
  1308. return new Pair (persister.ViewState, persister.ControlState);
  1309. }
  1310. internal void LoadPageViewState()
  1311. {
  1312. Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
  1313. if (sState != null) {
  1314. if (allow_load) {
  1315. #if NET_2_0
  1316. LoadPageControlState (sState.Second);
  1317. #endif
  1318. Pair vsr = sState.First as Pair;
  1319. if (vsr != null) {
  1320. LoadViewStateRecursive (vsr.First);
  1321. _requiresPostBackCopy = vsr.Second as ArrayList;
  1322. }
  1323. }
  1324. }
  1325. }
  1326. internal void SavePageViewState ()
  1327. {
  1328. if (!handleViewState)
  1329. return;
  1330. #if NET_2_0
  1331. object controlState = SavePageControlState ();
  1332. #endif
  1333. object viewState = SaveViewStateRecursive ();
  1334. object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
  1335. Pair vsr = null;
  1336. if (viewState != null || reqPostback != null)
  1337. vsr = new Pair (viewState, reqPostback);
  1338. Pair pair = new Pair ();
  1339. pair.First = vsr;
  1340. #if NET_2_0
  1341. pair.Second = controlState;
  1342. #else
  1343. pair.Second = null;
  1344. #endif
  1345. if (pair.First == null && pair.Second == null)
  1346. SavePageStateToPersistenceMedium (null);
  1347. else
  1348. SavePageStateToPersistenceMedium (pair);
  1349. }
  1350. public virtual void Validate ()
  1351. {
  1352. is_validated = true;
  1353. ValidateCollection (_validators);
  1354. }
  1355. #if NET_2_0
  1356. internal bool AreValidatorsUplevel () {
  1357. return AreValidatorsUplevel (String.Empty);
  1358. }
  1359. internal bool AreValidatorsUplevel (string valGroup)
  1360. #else
  1361. internal virtual bool AreValidatorsUplevel ()
  1362. #endif
  1363. {
  1364. bool uplevel = false;
  1365. foreach (IValidator v in Validators) {
  1366. BaseValidator bv = v as BaseValidator;
  1367. if (bv == null) continue;
  1368. #if NET_2_0
  1369. if (valGroup != bv.ValidationGroup)
  1370. continue;
  1371. #endif
  1372. if (bv.GetRenderUplevel()) {
  1373. uplevel = true;
  1374. break;
  1375. }
  1376. }
  1377. return uplevel;
  1378. }
  1379. bool ValidateCollection (ValidatorCollection validators)
  1380. {
  1381. #if NET_2_0
  1382. if (!_eventValidation)
  1383. return true;
  1384. #endif
  1385. if (validators == null || validators.Count == 0)
  1386. return true;
  1387. bool all_valid = true;
  1388. foreach (IValidator v in validators){
  1389. v.Validate ();
  1390. if (v.IsValid == false)
  1391. all_valid = false;
  1392. }
  1393. return all_valid;
  1394. }
  1395. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1396. public virtual void VerifyRenderingInServerForm (Control control)
  1397. {
  1398. if (_context == null)
  1399. return;
  1400. if (!renderingForm)
  1401. throw new HttpException ("Control '" +
  1402. control.ClientID +
  1403. "' of type '" +
  1404. control.GetType ().Name +
  1405. "' must be placed inside a form tag with runat=server.");
  1406. }
  1407. protected override void FrameworkInitialize ()
  1408. {
  1409. base.FrameworkInitialize ();
  1410. #if NET_2_0
  1411. InitializeStyleSheet ();
  1412. #endif
  1413. }
  1414. #endregion
  1415. #if NET_2_0
  1416. public
  1417. #else
  1418. internal
  1419. #endif
  1420. ClientScriptManager ClientScript {
  1421. get { return scriptManager; }
  1422. }
  1423. #if NET_2_0
  1424. static readonly object InitCompleteEvent = new object ();
  1425. static readonly object LoadCompleteEvent = new object ();
  1426. static readonly object PreInitEvent = new object ();
  1427. static readonly object PreLoadEvent = new object ();
  1428. static readonly object PreRenderCompleteEvent = new object ();
  1429. static readonly object SaveStateCompleteEvent = new object ();
  1430. int event_mask;
  1431. const int initcomplete_mask = 1;
  1432. const int loadcomplete_mask = 1 << 1;
  1433. const int preinit_mask = 1 << 2;
  1434. const int preload_mask = 1 << 3;
  1435. const int prerendercomplete_mask = 1 << 4;
  1436. const int savestatecomplete_mask = 1 << 5;
  1437. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1438. public event EventHandler InitComplete {
  1439. add {
  1440. event_mask |= initcomplete_mask;
  1441. Events.AddHandler (InitCompleteEvent, value);
  1442. }
  1443. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1444. }
  1445. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1446. public event EventHandler LoadComplete {
  1447. add {
  1448. event_mask |= loadcomplete_mask;
  1449. Events.AddHandler (LoadCompleteEvent, value);
  1450. }
  1451. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1452. }
  1453. public event EventHandler PreInit {
  1454. add {
  1455. event_mask |= preinit_mask;
  1456. Events.AddHandler (PreInitEvent, value);
  1457. }
  1458. remove { Events.RemoveHandler (PreInitEvent, value); }
  1459. }
  1460. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1461. public event EventHandler PreLoad {
  1462. add {
  1463. event_mask |= preload_mask;
  1464. Events.AddHandler (PreLoadEvent, value);
  1465. }
  1466. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1467. }
  1468. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1469. public event EventHandler PreRenderComplete {
  1470. add {
  1471. event_mask |= prerendercomplete_mask;
  1472. Events.AddHandler (PreRenderCompleteEvent, value);
  1473. }
  1474. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1475. }
  1476. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1477. public event EventHandler SaveStateComplete {
  1478. add {
  1479. event_mask |= savestatecomplete_mask;
  1480. Events.AddHandler (SaveStateCompleteEvent, value);
  1481. }
  1482. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1483. }
  1484. protected virtual void OnInitComplete (EventArgs e)
  1485. {
  1486. if ((event_mask & initcomplete_mask) != 0) {
  1487. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1488. if (eh != null) eh (this, e);
  1489. }
  1490. }
  1491. protected virtual void OnLoadComplete (EventArgs e)
  1492. {
  1493. if ((event_mask & loadcomplete_mask) != 0) {
  1494. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1495. if (eh != null) eh (this, e);
  1496. }
  1497. }
  1498. protected virtual void OnPreInit (EventArgs e)
  1499. {
  1500. if ((event_mask & preinit_mask) != 0) {
  1501. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1502. if (eh != null) eh (this, e);
  1503. }
  1504. }
  1505. protected virtual void OnPreLoad (EventArgs e)
  1506. {
  1507. if ((event_mask & preload_mask) != 0) {
  1508. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1509. if (eh != null) eh (this, e);
  1510. }
  1511. }
  1512. protected virtual void OnPreRenderComplete (EventArgs e)
  1513. {
  1514. if ((event_mask & prerendercomplete_mask) != 0) {
  1515. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1516. if (eh != null) eh (this, e);
  1517. }
  1518. if (Form == null)
  1519. return;
  1520. if (!Form.DetermineRenderUplevel ())
  1521. return;
  1522. /* figure out if we have some control we're going to focus */
  1523. if (String.IsNullOrEmpty (_focusedControlID)) {
  1524. _focusedControlID = Form.DefaultFocus;
  1525. if (String.IsNullOrEmpty (_focusedControlID))
  1526. _focusedControlID = Form.DefaultButton;
  1527. }
  1528. if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
  1529. RequiresPostBackScript ();
  1530. ClientScript.RegisterWebFormClientScript ();
  1531. if (!String.IsNullOrEmpty (_focusedControlID)) {
  1532. ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
  1533. String.Format ("<script type=\"text/javascript\">\n" +
  1534. "<!--\n" +
  1535. "WebForm_AutoFocus('{0}');// -->\n" +
  1536. "</script>\n", _focusedControlID));
  1537. }
  1538. if (Form.SubmitDisabledControls) {
  1539. ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
  1540. "javascript: return WebForm_OnSubmit();");
  1541. ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
  1542. @"<script language=""JavaScript"">
  1543. <!--
  1544. function WebForm_OnSubmit() {
  1545. WebForm_ReEnableControls();
  1546. return true;
  1547. } // -->
  1548. </script>");
  1549. }
  1550. }
  1551. }
  1552. protected virtual void OnSaveStateComplete (EventArgs e)
  1553. {
  1554. if ((event_mask & savestatecomplete_mask) != 0) {
  1555. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1556. if (eh != null) eh (this, e);
  1557. }
  1558. }
  1559. public HtmlForm Form {
  1560. get { return _form; }
  1561. }
  1562. internal void RegisterForm (HtmlForm form)
  1563. {
  1564. _form = form;
  1565. }
  1566. [BrowsableAttribute (false)]
  1567. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1568. public Page PreviousPage {
  1569. get {
  1570. if (_doLoadPreviousPage) {
  1571. _doLoadPreviousPage = false;
  1572. LoadPreviousPageReference ();
  1573. }
  1574. return previousPage;
  1575. }
  1576. }
  1577. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1578. [BrowsableAttribute (false)]
  1579. public bool IsCallback {
  1580. get { return isCallback; }
  1581. }
  1582. [BrowsableAttribute (false)]
  1583. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1584. public bool IsCrossPagePostBack {
  1585. get { return isCrossPagePostBack; }
  1586. }
  1587. string ProcessCallbackData ()
  1588. {
  1589. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1590. if (callbackTarget == null || callbackTarget.Length == 0)
  1591. throw new HttpException ("Callback target not provided.");
  1592. Control targetControl = FindControl (callbackTarget);
  1593. ICallbackEventHandler target = targetControl as ICallbackEventHandler;
  1594. if (target == null)
  1595. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1596. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1597. target.RaiseCallbackEvent (callbackArgument);
  1598. return target.GetCallbackResult ();
  1599. }
  1600. [BrowsableAttribute (false)]
  1601. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1602. public HtmlHead Header {
  1603. get { return htmlHeader; }
  1604. }
  1605. internal void SetHeader (HtmlHead header)
  1606. {
  1607. htmlHeader = header;
  1608. if (_title != null) {
  1609. htmlHeader.Title = _title;
  1610. _title = null;
  1611. }
  1612. }
  1613. [MonoTODO("Not Implemented")]
  1614. protected bool AsyncMode {
  1615. get {
  1616. throw new NotImplementedException ();
  1617. }
  1618. set {
  1619. throw new NotImplementedException ();
  1620. }
  1621. }
  1622. [MonoTODO ("Not Implemented")]
  1623. public TimeSpan AsyncTimeout {
  1624. get {
  1625. throw new NotImplementedException ();
  1626. }
  1627. set {
  1628. throw new NotImplementedException ();
  1629. }
  1630. }
  1631. [MonoTODO ("Not Implemented")]
  1632. public bool IsAsync {
  1633. get {
  1634. throw new NotImplementedException ();
  1635. }
  1636. }
  1637. [MonoTODO ("Not Implemented")]
  1638. protected internal virtual string UniqueFilePathSuffix {
  1639. get {
  1640. throw new NotImplementedException ();
  1641. }
  1642. }
  1643. [MonoTODO ("Not Implemented")]
  1644. public int MaxPageStateFieldLength {
  1645. get {
  1646. throw new NotImplementedException ();
  1647. }
  1648. set {
  1649. throw new NotImplementedException ();
  1650. }
  1651. }
  1652. [MonoTODO ("Not Implemented")]
  1653. public ViewStateEncryptionMode ViewStateEncryptionMode {
  1654. get {
  1655. throw new NotImplementedException ();
  1656. }
  1657. set {
  1658. throw new NotImplementedException ();
  1659. }
  1660. }
  1661. [MonoTODO ("Not Implemented")]
  1662. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
  1663. {
  1664. throw new NotImplementedException ();
  1665. }
  1666. [MonoTODO ("Not Implemented")]
  1667. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
  1668. {
  1669. throw new NotImplementedException ();
  1670. }
  1671. [MonoTODO ("Not Implemented")]
  1672. public void ExecuteRegisteredAsyncTasks ()
  1673. {
  1674. throw new NotImplementedException ();
  1675. }
  1676. [MonoTODO ("Not Implemented")]
  1677. public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
  1678. {
  1679. throw new NotImplementedException ();
  1680. }
  1681. [MonoTODO ("Not Implemented")]
  1682. public void RegisterRequiresViewStateEncryption ()
  1683. {
  1684. throw new NotImplementedException ();
  1685. }
  1686. void ApplyMasterPage ()
  1687. {
  1688. if (masterPageFile != null && masterPageFile.Length > 0) {
  1689. ArrayList appliedMasterPageFiles = new ArrayList ();
  1690. if (Master != null) {
  1691. MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
  1692. Master.Page = this;
  1693. Controls.Clear ();
  1694. Controls.Add (Master);
  1695. }
  1696. }
  1697. }
  1698. [DefaultValueAttribute ("")]
  1699. public virtual string MasterPageFile {
  1700. get { return masterPageFile; }
  1701. set {
  1702. masterPageFile = value;
  1703. masterPage = null;
  1704. }
  1705. }
  1706. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1707. [BrowsableAttribute (false)]
  1708. public MasterPage Master {
  1709. get {
  1710. if (Context == null || String.IsNullOrEmpty (masterPageFile))
  1711. return null;
  1712. if (masterPage == null)
  1713. masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
  1714. return masterPage;
  1715. }
  1716. }
  1717. public void SetFocus (string clientID)
  1718. {
  1719. if (String.IsNullOrEmpty (clientID))
  1720. throw new ArgumentNullException ("control");
  1721. if (_lifeCycle > PageLifeCycle.PreRender)
  1722. throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
  1723. if(Form==null)
  1724. throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
  1725. _focusedControlID = clientID;
  1726. }
  1727. public void SetFocus (Control control)
  1728. {
  1729. if (control == null)
  1730. throw new ArgumentNullException ("control");
  1731. SetFocus (control.ClientID);
  1732. }
  1733. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1734. public void RegisterRequiresControlState (Control control)
  1735. {
  1736. if (control == null)
  1737. throw new ArgumentNullException ("control");
  1738. if (RequiresControlState (control))
  1739. return;
  1740. if (requireStateControls == null)
  1741. requireStateControls = new ArrayList ();
  1742. int n = requireStateControls.Add (control);
  1743. if (_savedControlState == null || n >= _savedControlState.Length)
  1744. return;
  1745. for (Control parent = control.Parent; parent != null; parent = parent.Parent)
  1746. if (parent.IsChildControlStateCleared)
  1747. return;
  1748. object state = _savedControlState [n];
  1749. if (state != null)
  1750. control.LoadControlState (state);
  1751. }
  1752. public bool RequiresControlState (Control control)
  1753. {
  1754. if (requireStateControls == null) return false;
  1755. return requireStateControls.Contains (control);
  1756. }
  1757. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1758. public void UnregisterRequiresControlState (Control control)
  1759. {
  1760. if (requireStateControls != null)
  1761. requireStateControls.Remove (control);
  1762. }
  1763. public ValidatorCollection GetValidators (string validationGroup)
  1764. {
  1765. string valgr = validationGroup;
  1766. if (valgr == null)
  1767. valgr = String.Empty;
  1768. if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
  1769. ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
  1770. if (col == null) {
  1771. col = new ValidatorCollection ();
  1772. _validatorsByGroup [valgr] = col;
  1773. }
  1774. return col;
  1775. }
  1776. public virtual void Validate (string validationGroup)
  1777. {
  1778. is_validated = true;
  1779. if (validationGroup == null)
  1780. ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
  1781. else if (_validatorsByGroup != null) {
  1782. ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
  1783. }
  1784. }
  1785. object SavePageControlState ()
  1786. {
  1787. if (requireStateControls == null) return null;
  1788. object[] state = new object [requireStateControls.Count];
  1789. bool allNull = true;
  1790. for (int n=0; n<state.Length; n++) {
  1791. state [n] = ((Control) requireStateControls [n]).SaveControlState ();
  1792. if (state [n] != null) allNull = false;
  1793. }
  1794. if (allNull) return null;
  1795. else return state;
  1796. }
  1797. void LoadPageControlState (object data)
  1798. {
  1799. _savedControlState = (object []) data;
  1800. if (requireStateControls == null) return;
  1801. int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
  1802. for (int n=0; n < max; n++) {
  1803. Control ctl = (Control) requireStateControls [n];
  1804. ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
  1805. }
  1806. }
  1807. void LoadPreviousPageReference ()
  1808. {
  1809. if (_requestValueCollection != null) {
  1810. string prevPage = _requestValueCollection [PreviousPageID];
  1811. if (prevPage != null) {
  1812. previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  1813. previousPage.ProcessCrossPagePostBack (_context);
  1814. }
  1815. }
  1816. }
  1817. Hashtable contentTemplates;
  1818. [EditorBrowsable (EditorBrowsableState.Never)]
  1819. protected internal void AddContentTemplate (string templateName, ITemplate template)
  1820. {
  1821. if (contentTemplates == null)
  1822. contentTemplates = new Hashtable ();
  1823. contentTemplates [templateName] = template;
  1824. }
  1825. PageTheme _pageTheme;
  1826. internal PageTheme PageTheme {
  1827. get { return _pageTheme; }
  1828. }
  1829. PageTheme _styleSheetPageTheme;
  1830. internal PageTheme StyleSheetPageTheme {
  1831. get { return _styleSheetPageTheme; }
  1832. }
  1833. Stack dataItemCtx;
  1834. internal void PushDataItemContext (object o) {
  1835. if (dataItemCtx == null)
  1836. dataItemCtx = new Stack ();
  1837. dataItemCtx.Push (o);
  1838. }
  1839. internal void PopDataItemContext () {
  1840. if (dataItemCtx == null)
  1841. throw new InvalidOperationException ();
  1842. dataItemCtx.Pop ();
  1843. }
  1844. public object GetDataItem() {
  1845. if (dataItemCtx == null || dataItemCtx.Count == 0)
  1846. throw new InvalidOperationException ("No data item");
  1847. return dataItemCtx.Peek ();
  1848. }
  1849. protected internal override void OnInit (EventArgs e)
  1850. {
  1851. base.OnInit (e);
  1852. if (Header == null)
  1853. return;
  1854. ArrayList themes = new ArrayList();
  1855. if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
  1856. themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
  1857. if (PageTheme != null && PageTheme.GetStyleSheets () != null)
  1858. themes.AddRange (PageTheme.GetStyleSheets ());
  1859. foreach (string lss in themes) {
  1860. HtmlLink hl = new HtmlLink ();
  1861. hl.Href = ResolveUrl (lss);
  1862. hl.Attributes["type"] = "text/css";
  1863. hl.Attributes["rel"] = "stylesheet";
  1864. Header.Controls.Add (hl);
  1865. }
  1866. }
  1867. #endif
  1868. #if NET_2_0
  1869. [MonoTODO ("Not implemented. Only used by .net aspx parser")]
  1870. protected object GetWrappedFileDependencies (string [] list)
  1871. {
  1872. return null;
  1873. }
  1874. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  1875. protected virtual void InitializeCulture ()
  1876. {
  1877. }
  1878. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  1879. protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
  1880. {
  1881. }
  1882. #endif
  1883. }
  1884. }