Page.cs 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180
  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\tif(!ValidatorOnSubmit()) return;");
  855. writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
  856. writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
  857. writer.WriteLine ("\t\ttheForm.submit();");
  858. writer.WriteLine ("\t}");
  859. writer.WriteLine ("// -->");
  860. writer.WriteLine ("</script>");
  861. }
  862. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  863. {
  864. if (renderingForm)
  865. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  866. renderingForm = true;
  867. writer.WriteLine ();
  868. scriptManager.WriteHiddenFields (writer);
  869. if (requiresPostBackScript) {
  870. RenderPostBackScript (writer, formUniqueID);
  871. postBackScriptRendered = true;
  872. }
  873. if (handleViewState)
  874. writer.WriteLine ("<input type=\"hidden\" name=\"__VIEWSTATE\" value=\"{0}\" />", _savedViewState);
  875. scriptManager.WriteClientScriptBlocks (writer);
  876. }
  877. internal IStateFormatter GetFormatter ()
  878. {
  879. return new ObjectStateFormatter (this);
  880. }
  881. internal object GetSavedViewState ()
  882. {
  883. return _savedViewState;
  884. }
  885. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  886. {
  887. scriptManager.WriteArrayDeclares (writer);
  888. if (!postBackScriptRendered && requiresPostBackScript)
  889. RenderPostBackScript (writer, formUniqueID);
  890. #if NET_2_0
  891. scriptManager.SaveEventValidationState ();
  892. scriptManager.WriteExpandoAttributes (writer);
  893. #endif
  894. scriptManager.WriteHiddenFields (writer);
  895. scriptManager.WriteClientScriptIncludes (writer);
  896. scriptManager.WriteStartupScriptBlocks (writer);
  897. renderingForm = false;
  898. postBackScriptRendered = false;
  899. }
  900. private void ProcessPostData (NameValueCollection data, bool second)
  901. {
  902. if (data != null) {
  903. Hashtable used = new Hashtable ();
  904. foreach (string id in data.AllKeys){
  905. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
  906. continue;
  907. string real_id = id;
  908. int dot = real_id.IndexOf ('.');
  909. if (dot >= 1)
  910. real_id = real_id.Substring (0, dot);
  911. if (real_id == null || used.ContainsKey (real_id))
  912. continue;
  913. used.Add (real_id, real_id);
  914. Control ctrl = FindControl (real_id);
  915. if (ctrl != null){
  916. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  917. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  918. if (pbdh == null) {
  919. if (pbeh != null)
  920. RegisterRequiresRaiseEvent (pbeh);
  921. continue;
  922. }
  923. if (pbdh.LoadPostData (real_id, data) == true) {
  924. if (requiresPostDataChanged == null)
  925. requiresPostDataChanged = new ArrayList ();
  926. requiresPostDataChanged.Add (pbdh);
  927. }
  928. if (_requiresPostBackCopy != null)
  929. _requiresPostBackCopy.Remove (real_id);
  930. } else if (!second) {
  931. if (secondPostData == null)
  932. secondPostData = new NameValueCollection ();
  933. secondPostData.Add (real_id, data [id]);
  934. }
  935. }
  936. }
  937. ArrayList list1 = null;
  938. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  939. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  940. foreach (string id in handlers) {
  941. IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
  942. if (pbdh != null) {
  943. _requiresPostBackCopy.Remove (id);
  944. if (pbdh.LoadPostData (id, data)) {
  945. if (requiresPostDataChanged == null)
  946. requiresPostDataChanged = new ArrayList ();
  947. requiresPostDataChanged.Add (pbdh);
  948. }
  949. } else if (!second) {
  950. if (list1 == null)
  951. list1 = new ArrayList ();
  952. list1.Add (id);
  953. }
  954. }
  955. }
  956. _requiresPostBackCopy = second ? null : list1;
  957. if (second)
  958. secondPostData = null;
  959. }
  960. [EditorBrowsable (EditorBrowsableState.Never)]
  961. #if NET_2_0 || TARGET_JVM
  962. public virtual void ProcessRequest (HttpContext context)
  963. #else
  964. public void ProcessRequest (HttpContext context)
  965. #endif
  966. {
  967. #if NET_2_0
  968. _lifeCycle = PageLifeCycle.Unknown;
  969. #endif
  970. _context = context;
  971. if (clientTarget != null)
  972. Request.ClientTarget = clientTarget;
  973. WireupAutomaticEvents ();
  974. //-- Control execution lifecycle in the docs
  975. // Save culture information because it can be modified in FrameworkInitialize()
  976. CultureInfo culture = Thread.CurrentThread.CurrentCulture;
  977. CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
  978. FrameworkInitialize ();
  979. context.ErrorPage = _errorPage;
  980. try {
  981. InternalProcessRequest ();
  982. } catch (ThreadAbortException) {
  983. // Do nothing, just ignore it by now.
  984. } catch (Exception e) {
  985. context.AddError (e); // OnError might access LastError
  986. OnError (EventArgs.Empty);
  987. context.ClearError (e);
  988. // We want to remove that error, as we're rethrowing to stop
  989. // further processing.
  990. Trace.Warn ("Unhandled Exception", e.ToString (), e);
  991. throw;
  992. } finally {
  993. try {
  994. #if NET_2_0
  995. _lifeCycle = PageLifeCycle.Unload;
  996. #endif
  997. RenderTrace ();
  998. UnloadRecursive (true);
  999. #if NET_2_0
  1000. _lifeCycle = PageLifeCycle.End;
  1001. #endif
  1002. } catch {}
  1003. if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
  1004. Thread.CurrentThread.CurrentCulture = culture;
  1005. if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
  1006. Thread.CurrentThread.CurrentUICulture = uiculture;
  1007. }
  1008. }
  1009. #if NET_2_0
  1010. internal void ProcessCrossPagePostBack (HttpContext context)
  1011. {
  1012. isCrossPagePostBack = true;
  1013. ProcessRequest (context);
  1014. }
  1015. #endif
  1016. void InternalProcessRequest ()
  1017. {
  1018. _requestValueCollection = this.DeterminePostBackMode();
  1019. #if NET_2_0
  1020. _lifeCycle = PageLifeCycle.Start;
  1021. // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
  1022. if (_requestValueCollection != null) {
  1023. if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
  1024. _doLoadPreviousPage = true;
  1025. }
  1026. else {
  1027. isCallback = _requestValueCollection [CallbackArgumentID] != null;
  1028. isPostBack = !isCallback;
  1029. }
  1030. }
  1031. // if request was transfered from other page - track Prev. Page
  1032. previousPage = _context.LastPage;
  1033. _context.LastPage = this;
  1034. InitializeCulture ();
  1035. _lifeCycle = PageLifeCycle.PreInit;
  1036. OnPreInit (EventArgs.Empty);
  1037. InitializeTheme ();
  1038. ApplyMasterPage ();
  1039. _lifeCycle = PageLifeCycle.Init;
  1040. #endif
  1041. Trace.Write ("aspx.page", "Begin Init");
  1042. InitRecursive (null);
  1043. Trace.Write ("aspx.page", "End Init");
  1044. #if NET_2_0
  1045. _lifeCycle = PageLifeCycle.InitComplete;
  1046. OnInitComplete (EventArgs.Empty);
  1047. #endif
  1048. renderingForm = false;
  1049. #if NET_2_0
  1050. if (IsPostBack || IsCallback) {
  1051. _lifeCycle = PageLifeCycle.PreLoad;
  1052. if (_requestValueCollection != null)
  1053. scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
  1054. #else
  1055. if (IsPostBack) {
  1056. #endif
  1057. Trace.Write ("aspx.page", "Begin LoadViewState");
  1058. LoadPageViewState ();
  1059. Trace.Write ("aspx.page", "End LoadViewState");
  1060. Trace.Write ("aspx.page", "Begin ProcessPostData");
  1061. ProcessPostData (_requestValueCollection, false);
  1062. Trace.Write ("aspx.page", "End ProcessPostData");
  1063. }
  1064. #if NET_2_0
  1065. OnPreLoad (EventArgs.Empty);
  1066. _lifeCycle = PageLifeCycle.Load;
  1067. #endif
  1068. LoadRecursive ();
  1069. #if NET_2_0
  1070. if (IsPostBack || IsCallback) {
  1071. _lifeCycle = PageLifeCycle.ControlEvents;
  1072. #else
  1073. if (IsPostBack) {
  1074. #endif
  1075. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  1076. ProcessPostData (secondPostData, true);
  1077. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  1078. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  1079. RaiseChangedEvents ();
  1080. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  1081. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  1082. RaisePostBackEvents ();
  1083. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  1084. }
  1085. #if NET_2_0
  1086. _lifeCycle = PageLifeCycle.LoadComplete;
  1087. OnLoadComplete (EventArgs.Empty);
  1088. if (IsCrossPagePostBack)
  1089. return;
  1090. if (IsCallback) {
  1091. string result = ProcessCallbackData ();
  1092. HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
  1093. callbackOutput.Write (result);
  1094. callbackOutput.Flush ();
  1095. return;
  1096. }
  1097. _lifeCycle = PageLifeCycle.PreRender;
  1098. #endif
  1099. Trace.Write ("aspx.page", "Begin PreRender");
  1100. PreRenderRecursiveInternal ();
  1101. Trace.Write ("aspx.page", "End PreRender");
  1102. #if NET_2_0
  1103. _lifeCycle = PageLifeCycle.PreRenderComplete;
  1104. OnPreRenderComplete (EventArgs.Empty);
  1105. #endif
  1106. Trace.Write ("aspx.page", "Begin SaveViewState");
  1107. SavePageViewState ();
  1108. Trace.Write ("aspx.page", "End SaveViewState");
  1109. #if NET_2_0
  1110. _lifeCycle = PageLifeCycle.SaveStateComplete;
  1111. OnSaveStateComplete (EventArgs.Empty);
  1112. _lifeCycle = PageLifeCycle.Render;
  1113. #endif
  1114. //--
  1115. Trace.Write ("aspx.page", "Begin Render");
  1116. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1117. RenderControl (output);
  1118. Trace.Write ("aspx.page", "End Render");
  1119. }
  1120. private void RenderTrace ()
  1121. {
  1122. TraceManager traceManager = HttpRuntime.TraceManager;
  1123. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  1124. return;
  1125. Trace.SaveData ();
  1126. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  1127. return;
  1128. if (!traceManager.LocalOnly || Context.Request.IsLocal) {
  1129. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1130. Trace.Render (output);
  1131. }
  1132. }
  1133. #if NET_2_0
  1134. bool CheckForValidationSupport (Control targetControl)
  1135. {
  1136. if (targetControl == null)
  1137. return false;
  1138. Type type = targetControl.GetType ();
  1139. object[] attributes = type.GetCustomAttributes (true);
  1140. foreach (object attr in attributes)
  1141. if (attr is SupportsEventValidationAttribute)
  1142. return true;
  1143. return false;
  1144. }
  1145. #endif
  1146. void RaisePostBackEvents ()
  1147. {
  1148. #if NET_2_0
  1149. Control targetControl;
  1150. #endif
  1151. if (requiresRaiseEvent != null) {
  1152. #if NET_2_0
  1153. targetControl = requiresRaiseEvent as Control;
  1154. if (targetControl != null && CheckForValidationSupport (targetControl))
  1155. scriptManager.ValidateEvent (targetControl.UniqueID, null);
  1156. #endif
  1157. RaisePostBackEvent (requiresRaiseEvent, null);
  1158. return;
  1159. }
  1160. NameValueCollection postdata = _requestValueCollection;
  1161. if (postdata == null)
  1162. return;
  1163. string eventTarget = postdata [postEventSourceID];
  1164. if (eventTarget == null || eventTarget.Length == 0) {
  1165. Validate ();
  1166. return;
  1167. }
  1168. #if NET_2_0
  1169. targetControl = FindControl (eventTarget);
  1170. IPostBackEventHandler target = targetControl as IPostBackEventHandler;
  1171. #else
  1172. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  1173. #endif
  1174. if (target == null)
  1175. return;
  1176. string eventArgument = postdata [postEventArgumentID];
  1177. #if NET_2_0
  1178. if (CheckForValidationSupport (targetControl))
  1179. scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
  1180. #endif
  1181. RaisePostBackEvent (target, eventArgument);
  1182. }
  1183. internal void RaiseChangedEvents ()
  1184. {
  1185. if (requiresPostDataChanged == null)
  1186. return;
  1187. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1188. ipdh.RaisePostDataChangedEvent ();
  1189. requiresPostDataChanged = null;
  1190. }
  1191. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1192. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1193. {
  1194. sourceControl.RaisePostBackEvent (eventArgument);
  1195. }
  1196. #if NET_2_0
  1197. [Obsolete]
  1198. #endif
  1199. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1200. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1201. {
  1202. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1203. }
  1204. #if NET_2_0
  1205. [Obsolete]
  1206. #endif
  1207. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1208. public virtual void RegisterClientScriptBlock (string key, string script)
  1209. {
  1210. scriptManager.RegisterClientScriptBlock (key, script);
  1211. }
  1212. #if NET_2_0
  1213. [Obsolete]
  1214. #endif
  1215. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1216. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1217. {
  1218. scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  1219. }
  1220. [MonoTODO("Not implemented, Used in HtmlForm")]
  1221. internal void RegisterClientScriptFile (string a, string b, string c)
  1222. {
  1223. throw new NotImplementedException ();
  1224. }
  1225. #if NET_2_0
  1226. [Obsolete]
  1227. #endif
  1228. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1229. public void RegisterOnSubmitStatement (string key, string script)
  1230. {
  1231. scriptManager.RegisterOnSubmitStatement (key, script);
  1232. }
  1233. internal string GetSubmitStatements ()
  1234. {
  1235. return scriptManager.WriteSubmitStatements ();
  1236. }
  1237. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1238. public void RegisterRequiresPostBack (Control control)
  1239. {
  1240. if (_requiresPostBack == null)
  1241. _requiresPostBack = new ArrayList ();
  1242. if (_requiresPostBack.Contains (control.UniqueID))
  1243. return;
  1244. _requiresPostBack.Add (control.UniqueID);
  1245. }
  1246. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1247. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  1248. {
  1249. requiresRaiseEvent = control;
  1250. }
  1251. #if NET_2_0
  1252. [Obsolete]
  1253. #endif
  1254. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1255. public virtual void RegisterStartupScript (string key, string script)
  1256. {
  1257. scriptManager.RegisterStartupScript (key, script);
  1258. }
  1259. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1260. public void RegisterViewStateHandler ()
  1261. {
  1262. handleViewState = true;
  1263. }
  1264. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1265. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  1266. {
  1267. PageStatePersister persister = this.PageStatePersister;
  1268. if (persister == null)
  1269. return;
  1270. Pair pair = viewState as Pair;
  1271. if (pair != null) {
  1272. persister.ViewState = pair.First;
  1273. persister.ControlState = pair.Second;
  1274. } else
  1275. persister.ViewState = viewState;
  1276. persister.Save ();
  1277. }
  1278. internal string RawViewState {
  1279. get {
  1280. NameValueCollection postdata = _requestValueCollection;
  1281. string view_state;
  1282. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  1283. return null;
  1284. if (view_state == "")
  1285. return null;
  1286. return view_state;
  1287. }
  1288. set { _savedViewState = value; }
  1289. }
  1290. #if NET_2_0
  1291. protected virtual
  1292. #else
  1293. internal
  1294. #endif
  1295. PageStatePersister PageStatePersister {
  1296. get {
  1297. if (page_state_persister == null)
  1298. page_state_persister = new HiddenFieldPageStatePersister (this);
  1299. return page_state_persister;
  1300. }
  1301. }
  1302. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1303. protected virtual object LoadPageStateFromPersistenceMedium ()
  1304. {
  1305. PageStatePersister persister = this.PageStatePersister;
  1306. if (persister == null)
  1307. return null;
  1308. persister.Load ();
  1309. return new Pair (persister.ViewState, persister.ControlState);
  1310. }
  1311. internal void LoadPageViewState()
  1312. {
  1313. Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
  1314. if (sState != null) {
  1315. if (allow_load) {
  1316. #if NET_2_0
  1317. LoadPageControlState (sState.Second);
  1318. #endif
  1319. Pair vsr = sState.First as Pair;
  1320. if (vsr != null) {
  1321. LoadViewStateRecursive (vsr.First);
  1322. _requiresPostBackCopy = vsr.Second as ArrayList;
  1323. }
  1324. }
  1325. }
  1326. }
  1327. internal void SavePageViewState ()
  1328. {
  1329. if (!handleViewState)
  1330. return;
  1331. #if NET_2_0
  1332. object controlState = SavePageControlState ();
  1333. #endif
  1334. object viewState = SaveViewStateRecursive ();
  1335. object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
  1336. Pair vsr = null;
  1337. if (viewState != null || reqPostback != null)
  1338. vsr = new Pair (viewState, reqPostback);
  1339. Pair pair = new Pair ();
  1340. pair.First = vsr;
  1341. #if NET_2_0
  1342. pair.Second = controlState;
  1343. #else
  1344. pair.Second = null;
  1345. #endif
  1346. if (pair.First == null && pair.Second == null)
  1347. SavePageStateToPersistenceMedium (null);
  1348. else
  1349. SavePageStateToPersistenceMedium (pair);
  1350. }
  1351. public virtual void Validate ()
  1352. {
  1353. is_validated = true;
  1354. ValidateCollection (_validators);
  1355. }
  1356. #if NET_2_0
  1357. internal bool AreValidatorsUplevel () {
  1358. return AreValidatorsUplevel (String.Empty);
  1359. }
  1360. internal bool AreValidatorsUplevel (string valGroup)
  1361. #else
  1362. internal virtual bool AreValidatorsUplevel ()
  1363. #endif
  1364. {
  1365. bool uplevel = false;
  1366. foreach (IValidator v in Validators) {
  1367. BaseValidator bv = v as BaseValidator;
  1368. if (bv == null) continue;
  1369. #if NET_2_0
  1370. if (valGroup != bv.ValidationGroup)
  1371. continue;
  1372. #endif
  1373. if (bv.GetRenderUplevel()) {
  1374. uplevel = true;
  1375. break;
  1376. }
  1377. }
  1378. return uplevel;
  1379. }
  1380. bool ValidateCollection (ValidatorCollection validators)
  1381. {
  1382. #if NET_2_0
  1383. if (!_eventValidation)
  1384. return true;
  1385. #endif
  1386. if (validators == null || validators.Count == 0)
  1387. return true;
  1388. bool all_valid = true;
  1389. foreach (IValidator v in validators){
  1390. v.Validate ();
  1391. if (v.IsValid == false)
  1392. all_valid = false;
  1393. }
  1394. return all_valid;
  1395. }
  1396. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1397. public virtual void VerifyRenderingInServerForm (Control control)
  1398. {
  1399. if (_context == null)
  1400. return;
  1401. if (!renderingForm)
  1402. throw new HttpException ("Control '" +
  1403. control.ClientID +
  1404. "' of type '" +
  1405. control.GetType ().Name +
  1406. "' must be placed inside a form tag with runat=server.");
  1407. }
  1408. protected override void FrameworkInitialize ()
  1409. {
  1410. base.FrameworkInitialize ();
  1411. #if NET_2_0
  1412. InitializeStyleSheet ();
  1413. #endif
  1414. }
  1415. #endregion
  1416. #if NET_2_0
  1417. public
  1418. #else
  1419. internal
  1420. #endif
  1421. ClientScriptManager ClientScript {
  1422. get { return scriptManager; }
  1423. }
  1424. #if NET_2_0
  1425. static readonly object InitCompleteEvent = new object ();
  1426. static readonly object LoadCompleteEvent = new object ();
  1427. static readonly object PreInitEvent = new object ();
  1428. static readonly object PreLoadEvent = new object ();
  1429. static readonly object PreRenderCompleteEvent = new object ();
  1430. static readonly object SaveStateCompleteEvent = new object ();
  1431. int event_mask;
  1432. const int initcomplete_mask = 1;
  1433. const int loadcomplete_mask = 1 << 1;
  1434. const int preinit_mask = 1 << 2;
  1435. const int preload_mask = 1 << 3;
  1436. const int prerendercomplete_mask = 1 << 4;
  1437. const int savestatecomplete_mask = 1 << 5;
  1438. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1439. public event EventHandler InitComplete {
  1440. add {
  1441. event_mask |= initcomplete_mask;
  1442. Events.AddHandler (InitCompleteEvent, value);
  1443. }
  1444. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1445. }
  1446. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1447. public event EventHandler LoadComplete {
  1448. add {
  1449. event_mask |= loadcomplete_mask;
  1450. Events.AddHandler (LoadCompleteEvent, value);
  1451. }
  1452. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1453. }
  1454. public event EventHandler PreInit {
  1455. add {
  1456. event_mask |= preinit_mask;
  1457. Events.AddHandler (PreInitEvent, value);
  1458. }
  1459. remove { Events.RemoveHandler (PreInitEvent, value); }
  1460. }
  1461. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1462. public event EventHandler PreLoad {
  1463. add {
  1464. event_mask |= preload_mask;
  1465. Events.AddHandler (PreLoadEvent, value);
  1466. }
  1467. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1468. }
  1469. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1470. public event EventHandler PreRenderComplete {
  1471. add {
  1472. event_mask |= prerendercomplete_mask;
  1473. Events.AddHandler (PreRenderCompleteEvent, value);
  1474. }
  1475. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1476. }
  1477. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1478. public event EventHandler SaveStateComplete {
  1479. add {
  1480. event_mask |= savestatecomplete_mask;
  1481. Events.AddHandler (SaveStateCompleteEvent, value);
  1482. }
  1483. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1484. }
  1485. protected virtual void OnInitComplete (EventArgs e)
  1486. {
  1487. if ((event_mask & initcomplete_mask) != 0) {
  1488. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1489. if (eh != null) eh (this, e);
  1490. }
  1491. }
  1492. protected virtual void OnLoadComplete (EventArgs e)
  1493. {
  1494. if ((event_mask & loadcomplete_mask) != 0) {
  1495. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1496. if (eh != null) eh (this, e);
  1497. }
  1498. }
  1499. protected virtual void OnPreInit (EventArgs e)
  1500. {
  1501. if ((event_mask & preinit_mask) != 0) {
  1502. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1503. if (eh != null) eh (this, e);
  1504. }
  1505. }
  1506. protected virtual void OnPreLoad (EventArgs e)
  1507. {
  1508. if ((event_mask & preload_mask) != 0) {
  1509. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1510. if (eh != null) eh (this, e);
  1511. }
  1512. }
  1513. protected virtual void OnPreRenderComplete (EventArgs e)
  1514. {
  1515. if ((event_mask & prerendercomplete_mask) != 0) {
  1516. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1517. if (eh != null) eh (this, e);
  1518. }
  1519. if (Form == null)
  1520. return;
  1521. if (!Form.DetermineRenderUplevel ())
  1522. return;
  1523. /* figure out if we have some control we're going to focus */
  1524. if (String.IsNullOrEmpty (_focusedControlID)) {
  1525. _focusedControlID = Form.DefaultFocus;
  1526. if (String.IsNullOrEmpty (_focusedControlID))
  1527. _focusedControlID = Form.DefaultButton;
  1528. }
  1529. if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
  1530. RequiresPostBackScript ();
  1531. ClientScript.RegisterWebFormClientScript ();
  1532. if (!String.IsNullOrEmpty (_focusedControlID)) {
  1533. ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
  1534. String.Format ("<script type=\"text/javascript\">\n" +
  1535. "<!--\n" +
  1536. "WebForm_AutoFocus('{0}');// -->\n" +
  1537. "</script>\n", _focusedControlID));
  1538. }
  1539. if (Form.SubmitDisabledControls) {
  1540. ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
  1541. "javascript: return WebForm_OnSubmit();");
  1542. ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
  1543. @"<script language=""JavaScript"">
  1544. <!--
  1545. function WebForm_OnSubmit() {
  1546. WebForm_ReEnableControls();
  1547. return true;
  1548. } // -->
  1549. </script>");
  1550. }
  1551. }
  1552. }
  1553. protected virtual void OnSaveStateComplete (EventArgs e)
  1554. {
  1555. if ((event_mask & savestatecomplete_mask) != 0) {
  1556. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1557. if (eh != null) eh (this, e);
  1558. }
  1559. }
  1560. public HtmlForm Form {
  1561. get { return _form; }
  1562. }
  1563. internal void RegisterForm (HtmlForm form)
  1564. {
  1565. _form = form;
  1566. }
  1567. [BrowsableAttribute (false)]
  1568. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1569. public Page PreviousPage {
  1570. get {
  1571. if (_doLoadPreviousPage) {
  1572. _doLoadPreviousPage = false;
  1573. LoadPreviousPageReference ();
  1574. }
  1575. return previousPage;
  1576. }
  1577. }
  1578. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1579. [BrowsableAttribute (false)]
  1580. public bool IsCallback {
  1581. get { return isCallback; }
  1582. }
  1583. [BrowsableAttribute (false)]
  1584. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1585. public bool IsCrossPagePostBack {
  1586. get { return isCrossPagePostBack; }
  1587. }
  1588. string ProcessCallbackData ()
  1589. {
  1590. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1591. if (callbackTarget == null || callbackTarget.Length == 0)
  1592. throw new HttpException ("Callback target not provided.");
  1593. Control targetControl = FindControl (callbackTarget);
  1594. ICallbackEventHandler target = targetControl as ICallbackEventHandler;
  1595. if (target == null)
  1596. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1597. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1598. target.RaiseCallbackEvent (callbackArgument);
  1599. return target.GetCallbackResult ();
  1600. }
  1601. [BrowsableAttribute (false)]
  1602. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1603. public HtmlHead Header {
  1604. get { return htmlHeader; }
  1605. }
  1606. internal void SetHeader (HtmlHead header)
  1607. {
  1608. htmlHeader = header;
  1609. if (_title != null) {
  1610. htmlHeader.Title = _title;
  1611. _title = null;
  1612. }
  1613. }
  1614. [MonoTODO("Not Implemented")]
  1615. protected bool AsyncMode {
  1616. get {
  1617. throw new NotImplementedException ();
  1618. }
  1619. set {
  1620. throw new NotImplementedException ();
  1621. }
  1622. }
  1623. [MonoTODO ("Not Implemented")]
  1624. public TimeSpan AsyncTimeout {
  1625. get {
  1626. throw new NotImplementedException ();
  1627. }
  1628. set {
  1629. throw new NotImplementedException ();
  1630. }
  1631. }
  1632. [MonoTODO ("Not Implemented")]
  1633. public bool IsAsync {
  1634. get {
  1635. throw new NotImplementedException ();
  1636. }
  1637. }
  1638. [MonoTODO ("Not Implemented")]
  1639. protected internal virtual string UniqueFilePathSuffix {
  1640. get {
  1641. throw new NotImplementedException ();
  1642. }
  1643. }
  1644. [MonoTODO ("Not Implemented")]
  1645. public int MaxPageStateFieldLength {
  1646. get {
  1647. throw new NotImplementedException ();
  1648. }
  1649. set {
  1650. throw new NotImplementedException ();
  1651. }
  1652. }
  1653. [MonoTODO ("Not Implemented")]
  1654. public ViewStateEncryptionMode ViewStateEncryptionMode {
  1655. get {
  1656. throw new NotImplementedException ();
  1657. }
  1658. set {
  1659. throw new NotImplementedException ();
  1660. }
  1661. }
  1662. [MonoTODO ("Not Implemented")]
  1663. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
  1664. {
  1665. throw new NotImplementedException ();
  1666. }
  1667. [MonoTODO ("Not Implemented")]
  1668. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
  1669. {
  1670. throw new NotImplementedException ();
  1671. }
  1672. [MonoTODO ("Not Implemented")]
  1673. public void ExecuteRegisteredAsyncTasks ()
  1674. {
  1675. throw new NotImplementedException ();
  1676. }
  1677. [MonoTODO ("Not Implemented")]
  1678. public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
  1679. {
  1680. throw new NotImplementedException ();
  1681. }
  1682. [MonoTODO ("Not Implemented")]
  1683. public void RegisterRequiresViewStateEncryption ()
  1684. {
  1685. throw new NotImplementedException ();
  1686. }
  1687. void ApplyMasterPage ()
  1688. {
  1689. if (masterPageFile != null && masterPageFile.Length > 0) {
  1690. ArrayList appliedMasterPageFiles = new ArrayList ();
  1691. if (Master != null) {
  1692. MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
  1693. Master.Page = this;
  1694. Controls.Clear ();
  1695. Controls.Add (Master);
  1696. }
  1697. }
  1698. }
  1699. [DefaultValueAttribute ("")]
  1700. public virtual string MasterPageFile {
  1701. get { return masterPageFile; }
  1702. set {
  1703. masterPageFile = value;
  1704. masterPage = null;
  1705. }
  1706. }
  1707. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1708. [BrowsableAttribute (false)]
  1709. public MasterPage Master {
  1710. get {
  1711. if (Context == null || String.IsNullOrEmpty (masterPageFile))
  1712. return null;
  1713. if (masterPage == null)
  1714. masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
  1715. return masterPage;
  1716. }
  1717. }
  1718. public void SetFocus (string clientID)
  1719. {
  1720. if (String.IsNullOrEmpty (clientID))
  1721. throw new ArgumentNullException ("control");
  1722. if (_lifeCycle > PageLifeCycle.PreRender)
  1723. throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
  1724. if(Form==null)
  1725. throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
  1726. _focusedControlID = clientID;
  1727. }
  1728. public void SetFocus (Control control)
  1729. {
  1730. if (control == null)
  1731. throw new ArgumentNullException ("control");
  1732. SetFocus (control.ClientID);
  1733. }
  1734. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1735. public void RegisterRequiresControlState (Control control)
  1736. {
  1737. if (control == null)
  1738. throw new ArgumentNullException ("control");
  1739. if (RequiresControlState (control))
  1740. return;
  1741. if (requireStateControls == null)
  1742. requireStateControls = new ArrayList ();
  1743. int n = requireStateControls.Add (control);
  1744. if (_savedControlState == null || n >= _savedControlState.Length)
  1745. return;
  1746. for (Control parent = control.Parent; parent != null; parent = parent.Parent)
  1747. if (parent.IsChildControlStateCleared)
  1748. return;
  1749. object state = _savedControlState [n];
  1750. if (state != null)
  1751. control.LoadControlState (state);
  1752. }
  1753. public bool RequiresControlState (Control control)
  1754. {
  1755. if (requireStateControls == null) return false;
  1756. return requireStateControls.Contains (control);
  1757. }
  1758. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1759. public void UnregisterRequiresControlState (Control control)
  1760. {
  1761. if (requireStateControls != null)
  1762. requireStateControls.Remove (control);
  1763. }
  1764. public ValidatorCollection GetValidators (string validationGroup)
  1765. {
  1766. string valgr = validationGroup;
  1767. if (valgr == null)
  1768. valgr = String.Empty;
  1769. if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
  1770. ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
  1771. if (col == null) {
  1772. col = new ValidatorCollection ();
  1773. _validatorsByGroup [valgr] = col;
  1774. }
  1775. return col;
  1776. }
  1777. public virtual void Validate (string validationGroup)
  1778. {
  1779. is_validated = true;
  1780. if (validationGroup == null)
  1781. ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
  1782. else if (_validatorsByGroup != null) {
  1783. ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
  1784. }
  1785. }
  1786. object SavePageControlState ()
  1787. {
  1788. if (requireStateControls == null) return null;
  1789. object[] state = new object [requireStateControls.Count];
  1790. bool allNull = true;
  1791. for (int n=0; n<state.Length; n++) {
  1792. state [n] = ((Control) requireStateControls [n]).SaveControlState ();
  1793. if (state [n] != null) allNull = false;
  1794. }
  1795. if (allNull) return null;
  1796. else return state;
  1797. }
  1798. void LoadPageControlState (object data)
  1799. {
  1800. _savedControlState = (object []) data;
  1801. if (requireStateControls == null) return;
  1802. int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
  1803. for (int n=0; n < max; n++) {
  1804. Control ctl = (Control) requireStateControls [n];
  1805. ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
  1806. }
  1807. }
  1808. void LoadPreviousPageReference ()
  1809. {
  1810. if (_requestValueCollection != null) {
  1811. string prevPage = _requestValueCollection [PreviousPageID];
  1812. if (prevPage != null) {
  1813. previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  1814. previousPage.ProcessCrossPagePostBack (_context);
  1815. }
  1816. }
  1817. }
  1818. Hashtable contentTemplates;
  1819. [EditorBrowsable (EditorBrowsableState.Never)]
  1820. protected internal void AddContentTemplate (string templateName, ITemplate template)
  1821. {
  1822. if (contentTemplates == null)
  1823. contentTemplates = new Hashtable ();
  1824. contentTemplates [templateName] = template;
  1825. }
  1826. PageTheme _pageTheme;
  1827. internal PageTheme PageTheme {
  1828. get { return _pageTheme; }
  1829. }
  1830. PageTheme _styleSheetPageTheme;
  1831. internal PageTheme StyleSheetPageTheme {
  1832. get { return _styleSheetPageTheme; }
  1833. }
  1834. Stack dataItemCtx;
  1835. internal void PushDataItemContext (object o) {
  1836. if (dataItemCtx == null)
  1837. dataItemCtx = new Stack ();
  1838. dataItemCtx.Push (o);
  1839. }
  1840. internal void PopDataItemContext () {
  1841. if (dataItemCtx == null)
  1842. throw new InvalidOperationException ();
  1843. dataItemCtx.Pop ();
  1844. }
  1845. public object GetDataItem() {
  1846. if (dataItemCtx == null || dataItemCtx.Count == 0)
  1847. throw new InvalidOperationException ("No data item");
  1848. return dataItemCtx.Peek ();
  1849. }
  1850. protected internal override void OnInit (EventArgs e)
  1851. {
  1852. base.OnInit (e);
  1853. if (Header == null)
  1854. return;
  1855. ArrayList themes = new ArrayList();
  1856. if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
  1857. themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
  1858. if (PageTheme != null && PageTheme.GetStyleSheets () != null)
  1859. themes.AddRange (PageTheme.GetStyleSheets ());
  1860. foreach (string lss in themes) {
  1861. HtmlLink hl = new HtmlLink ();
  1862. hl.Href = ResolveUrl (lss);
  1863. hl.Attributes["type"] = "text/css";
  1864. hl.Attributes["rel"] = "stylesheet";
  1865. Header.Controls.Add (hl);
  1866. }
  1867. }
  1868. #endif
  1869. #if NET_2_0
  1870. [MonoTODO ("Not implemented. Only used by .net aspx parser")]
  1871. protected object GetWrappedFileDependencies (string [] list)
  1872. {
  1873. return null;
  1874. }
  1875. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  1876. protected virtual void InitializeCulture ()
  1877. {
  1878. }
  1879. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  1880. protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
  1881. {
  1882. }
  1883. #endif
  1884. }
  1885. }