Page.cs 57 KB

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