Page.cs 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735
  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. using System.Collections.Generic;
  54. using System.Reflection;
  55. #endif
  56. namespace System.Web.UI
  57. {
  58. // CAS
  59. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  60. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  61. #if !NET_2_0
  62. [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
  63. #endif
  64. [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
  65. [ToolboxItem (false)]
  66. #if NET_2_0
  67. [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
  68. #else
  69. [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
  70. #endif
  71. public partial class Page : TemplateControl, IHttpHandler
  72. {
  73. static string machineKeyConfigPath = "system.web/machineKey";
  74. #if NET_2_0
  75. private bool _eventValidation = true;
  76. private object [] _savedControlState;
  77. private bool _doLoadPreviousPage;
  78. string _focusedControlID;
  79. bool _hasEnabledControlArray;
  80. #endif
  81. private bool _viewState = true;
  82. private bool _viewStateMac;
  83. private string _errorPage;
  84. private bool is_validated;
  85. private bool _smartNavigation;
  86. private int _transactionMode;
  87. private ValidatorCollection _validators;
  88. private bool renderingForm;
  89. private string _savedViewState;
  90. private ArrayList _requiresPostBack;
  91. private ArrayList _requiresPostBackCopy;
  92. private ArrayList requiresPostDataChanged;
  93. private IPostBackEventHandler requiresRaiseEvent;
  94. private NameValueCollection secondPostData;
  95. private bool requiresPostBackScript;
  96. private bool postBackScriptRendered;
  97. bool handleViewState;
  98. string viewStateUserKey;
  99. NameValueCollection _requestValueCollection;
  100. string clientTarget;
  101. ClientScriptManager scriptManager;
  102. bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
  103. PageStatePersister page_state_persister;
  104. CultureInfo _appCulture;
  105. CultureInfo _appUICulture;
  106. // The initial context
  107. private HttpContext _context;
  108. // cached from the initial context
  109. HttpApplicationState _application;
  110. HttpResponse _response;
  111. HttpRequest _request;
  112. Cache _cache;
  113. HttpSessionState _session;
  114. [EditorBrowsable (EditorBrowsableState.Never)]
  115. #if NET_2_0
  116. public
  117. #else
  118. protected
  119. #endif
  120. const string postEventArgumentID = "__EVENTARGUMENT";
  121. [EditorBrowsable (EditorBrowsableState.Never)]
  122. #if NET_2_0
  123. public
  124. #else
  125. protected
  126. #endif
  127. const string postEventSourceID = "__EVENTTARGET";
  128. #if NET_2_0
  129. const string ScrollPositionXID = "__SCROLLPOSITIONX";
  130. const string ScrollPositionYID = "__SCROLLPOSITIONY";
  131. const string EnabledControlArrayID = "__enabledControlArray";
  132. #endif
  133. #if NET_2_0
  134. internal const string LastFocusID = "__LASTFOCUS";
  135. internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
  136. internal const string CallbackSourceID = "__CALLBACKTARGET";
  137. internal const string PreviousPageID = "__PREVIOUSPAGE";
  138. HtmlHead htmlHeader;
  139. MasterPage masterPage;
  140. string masterPageFile;
  141. Page previousPage;
  142. bool isCrossPagePostBack;
  143. bool isPostBack;
  144. bool isCallback;
  145. ArrayList requireStateControls;
  146. HtmlForm _form;
  147. string _title;
  148. string _theme;
  149. string _styleSheetTheme;
  150. Hashtable items;
  151. bool _maintainScrollPositionOnPostBack;
  152. private bool asyncMode = false;
  153. private TimeSpan asyncTimeout;
  154. private const double DefaultAsyncTimeout = 45.0;
  155. private List<PageAsyncTask> parallelTasks;
  156. private List<PageAsyncTask> serialTasks;
  157. private ViewStateEncryptionMode viewStateEncryptionMode;
  158. private bool controlRegisteredForViewStateEncryption = false;
  159. #endif
  160. #region Constructor
  161. public Page ()
  162. {
  163. scriptManager = new ClientScriptManager (this);
  164. Page = this;
  165. ID = "__Page";
  166. #if NET_2_0
  167. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  168. if (ps != null) {
  169. asyncTimeout = ps.AsyncTimeout;
  170. viewStateEncryptionMode = ps.ViewStateEncryptionMode;
  171. } else {
  172. asyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
  173. viewStateEncryptionMode = ViewStateEncryptionMode.Auto;
  174. }
  175. #endif
  176. }
  177. #endregion
  178. #region Properties
  179. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  180. [Browsable (false)]
  181. public HttpApplicationState Application {
  182. get { return _application; }
  183. }
  184. [EditorBrowsable (EditorBrowsableState.Never)]
  185. protected bool AspCompatMode {
  186. #if NET_2_0
  187. get { return false; }
  188. #endif
  189. set { throw new NotImplementedException (); }
  190. }
  191. [EditorBrowsable (EditorBrowsableState.Never)]
  192. #if NET_2_0
  193. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  194. [BrowsableAttribute (false)]
  195. public bool Buffer {
  196. get { return Response.BufferOutput; }
  197. set { Response.BufferOutput = value; }
  198. }
  199. #else
  200. protected bool Buffer {
  201. set { Response.BufferOutput = value; }
  202. }
  203. #endif
  204. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  205. [Browsable (false)]
  206. public Cache Cache {
  207. get {
  208. if (_cache == null)
  209. throw new HttpException ("Cache is not available.");
  210. return _cache;
  211. }
  212. }
  213. #if NET_2_0
  214. [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
  215. #endif
  216. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  217. [Browsable (false), DefaultValue ("")]
  218. [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
  219. public string ClientTarget {
  220. get { return (clientTarget == null) ? "" : clientTarget; }
  221. set {
  222. clientTarget = value;
  223. if (value == "")
  224. clientTarget = null;
  225. }
  226. }
  227. [EditorBrowsable (EditorBrowsableState.Never)]
  228. #if NET_2_0
  229. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  230. [BrowsableAttribute (false)]
  231. public int CodePage {
  232. get { return Response.ContentEncoding.CodePage; }
  233. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  234. }
  235. #else
  236. protected int CodePage {
  237. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  238. }
  239. #endif
  240. [EditorBrowsable (EditorBrowsableState.Never)]
  241. #if NET_2_0
  242. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  243. [BrowsableAttribute (false)]
  244. public string ContentType {
  245. get { return Response.ContentType; }
  246. set { Response.ContentType = value; }
  247. }
  248. #else
  249. protected string ContentType {
  250. set { Response.ContentType = value; }
  251. }
  252. #endif
  253. protected override HttpContext Context {
  254. get {
  255. if (_context == null)
  256. return HttpContext.Current;
  257. return _context;
  258. }
  259. }
  260. #if NET_2_0
  261. [EditorBrowsable (EditorBrowsableState.Advanced)]
  262. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  263. [BrowsableAttribute (false)]
  264. public string Culture {
  265. get { return Thread.CurrentThread.CurrentCulture.Name; }
  266. set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
  267. }
  268. #else
  269. [EditorBrowsable (EditorBrowsableState.Never)]
  270. protected string Culture {
  271. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  272. }
  273. #endif
  274. #if NET_2_0
  275. public virtual bool EnableEventValidation {
  276. get { return _eventValidation; }
  277. set {
  278. if (IsInited)
  279. throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
  280. _eventValidation = value;
  281. }
  282. }
  283. #endif
  284. [Browsable (false)]
  285. public override bool EnableViewState {
  286. get { return _viewState; }
  287. set { _viewState = value; }
  288. }
  289. #if NET_2_0
  290. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  291. [BrowsableAttribute (false)]
  292. #endif
  293. [EditorBrowsable (EditorBrowsableState.Never)]
  294. #if NET_2_0
  295. public
  296. #else
  297. protected
  298. #endif
  299. bool EnableViewStateMac {
  300. get { return _viewStateMac; }
  301. set { _viewStateMac = value; }
  302. }
  303. #if NET_1_1
  304. internal bool EnableViewStateMacInternal {
  305. get { return _viewStateMac; }
  306. set { _viewStateMac = value; }
  307. }
  308. #endif
  309. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  310. [Browsable (false), DefaultValue ("")]
  311. [WebSysDescription ("The URL of a page used for error redirection.")]
  312. public string ErrorPage {
  313. get { return _errorPage; }
  314. set {
  315. HttpContext ctx = Context;
  316. _errorPage = value;
  317. if (ctx != null)
  318. ctx.ErrorPage = value;
  319. }
  320. }
  321. #if NET_2_0
  322. [Obsolete]
  323. #endif
  324. [EditorBrowsable (EditorBrowsableState.Never)]
  325. protected ArrayList FileDependencies {
  326. set {
  327. if (Response != null)
  328. Response.AddFileDependencies (value);
  329. }
  330. }
  331. [Browsable (false)]
  332. #if NET_2_0
  333. [EditorBrowsable (EditorBrowsableState.Never)]
  334. #endif
  335. public override string ID {
  336. get { return base.ID; }
  337. set { base.ID = value; }
  338. }
  339. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  340. [Browsable (false)]
  341. public bool IsPostBack {
  342. get {
  343. #if NET_2_0
  344. return isPostBack;
  345. #else
  346. return _requestValueCollection != null;
  347. #endif
  348. }
  349. }
  350. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  351. public bool IsReusable {
  352. get { return false; }
  353. }
  354. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  355. [Browsable (false)]
  356. public bool IsValid {
  357. get {
  358. if (!is_validated)
  359. throw new HttpException (Locale.GetText ("Page hasn't been validated."));
  360. #if NET_2_0
  361. foreach (IValidator val in Validators)
  362. if (!val.IsValid)
  363. return false;
  364. return true;
  365. #else
  366. return ValidateCollection (_validators);
  367. #endif
  368. }
  369. }
  370. #if NET_2_0
  371. public IDictionary Items {
  372. get {
  373. if (items == null)
  374. items = new Hashtable ();
  375. return items;
  376. }
  377. }
  378. #endif
  379. [EditorBrowsable (EditorBrowsableState.Never)]
  380. #if NET_2_0
  381. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  382. [BrowsableAttribute (false)]
  383. public int LCID {
  384. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  385. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  386. }
  387. #else
  388. protected int LCID {
  389. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  390. }
  391. #endif
  392. #if NET_2_0
  393. [Browsable (false)]
  394. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  395. public bool MaintainScrollPositionOnPostBack {
  396. get { return _maintainScrollPositionOnPostBack; }
  397. set { _maintainScrollPositionOnPostBack = value; }
  398. }
  399. #endif
  400. #if NET_2_0
  401. public PageAdapter PageAdapter {
  402. get {
  403. return (PageAdapter)Adapter;
  404. }
  405. }
  406. #endif
  407. #if !TARGET_J2EE
  408. internal string theForm {
  409. get {
  410. return "theForm";
  411. }
  412. }
  413. internal bool IsMultiForm {
  414. get { return false; }
  415. }
  416. #endif
  417. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  418. [Browsable (false)]
  419. public HttpRequest Request {
  420. get {
  421. if (_request == null)
  422. throw new HttpException("Request is not available in this context.");
  423. return _request;
  424. }
  425. }
  426. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  427. [Browsable (false)]
  428. public HttpResponse Response {
  429. get {
  430. if (_response == null)
  431. throw new HttpException ("Response is not available in this context.");
  432. return _response;
  433. }
  434. }
  435. [EditorBrowsable (EditorBrowsableState.Never)]
  436. #if NET_2_0
  437. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  438. [BrowsableAttribute (false)]
  439. public string ResponseEncoding {
  440. get { return Response.ContentEncoding.WebName; }
  441. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  442. }
  443. #else
  444. protected string ResponseEncoding {
  445. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  446. }
  447. #endif
  448. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  449. [Browsable (false)]
  450. public HttpServerUtility Server {
  451. get { return Context.Server; }
  452. }
  453. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  454. [Browsable (false)]
  455. public virtual HttpSessionState Session {
  456. get {
  457. if (_session != null)
  458. return _session;
  459. try {
  460. _session = Context.Session;
  461. } catch {
  462. // ignore, should not throw
  463. }
  464. if (_session == null)
  465. throw new HttpException ("Session state can only be used " +
  466. "when enableSessionState is set to true, either " +
  467. "in a configuration file or in the Page directive.");
  468. return _session;
  469. }
  470. }
  471. #if NET_2_0
  472. [FilterableAttribute (false)]
  473. [Obsolete]
  474. #endif
  475. [Browsable (false)]
  476. public bool SmartNavigation {
  477. get { return _smartNavigation; }
  478. set { _smartNavigation = value; }
  479. }
  480. #if NET_2_0
  481. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  482. [Filterable (false)]
  483. [Browsable (false)]
  484. public virtual string StyleSheetTheme {
  485. get { return _styleSheetTheme; }
  486. set { _styleSheetTheme = value; }
  487. }
  488. [Browsable (false)]
  489. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  490. public virtual string Theme {
  491. get { return _theme; }
  492. set { _theme = value; }
  493. }
  494. void InitializeStyleSheet ()
  495. {
  496. if (_styleSheetTheme == null) {
  497. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  498. if (ps != null)
  499. _styleSheetTheme = ps.StyleSheetTheme;
  500. }
  501. if (_styleSheetTheme != null && _styleSheetTheme != "")
  502. _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, Context);
  503. }
  504. void InitializeTheme ()
  505. {
  506. if (_theme == null) {
  507. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  508. if (ps != null)
  509. _theme = ps.Theme;
  510. }
  511. if (_theme != null && _theme != "") {
  512. _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, Context);
  513. _pageTheme.SetPage (this);
  514. }
  515. }
  516. #endif
  517. #if NET_2_0
  518. [Localizable (true)]
  519. [Bindable (true)]
  520. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  521. public string Title {
  522. get {
  523. if (_title == null) {
  524. if (htmlHeader != null)
  525. return htmlHeader.Title;
  526. return String.Empty;
  527. }
  528. return _title;
  529. }
  530. set {
  531. if (htmlHeader != null)
  532. htmlHeader.Title = value;
  533. else
  534. _title = value;
  535. }
  536. }
  537. #endif
  538. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  539. [Browsable (false)]
  540. public TraceContext Trace {
  541. get { return Context.Trace; }
  542. }
  543. [EditorBrowsable (EditorBrowsableState.Never)]
  544. #if NET_2_0
  545. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  546. [BrowsableAttribute (false)]
  547. public bool TraceEnabled {
  548. get { return Trace.IsEnabled; }
  549. set { Trace.IsEnabled = value; }
  550. }
  551. #else
  552. protected bool TraceEnabled {
  553. set { Trace.IsEnabled = value; }
  554. }
  555. #endif
  556. [EditorBrowsable (EditorBrowsableState.Never)]
  557. #if NET_2_0
  558. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  559. [BrowsableAttribute (false)]
  560. public TraceMode TraceModeValue {
  561. get { return Trace.TraceMode; }
  562. set { Trace.TraceMode = value; }
  563. }
  564. #else
  565. protected TraceMode TraceModeValue {
  566. set { Trace.TraceMode = value; }
  567. }
  568. #endif
  569. [EditorBrowsable (EditorBrowsableState.Never)]
  570. protected int TransactionMode {
  571. #if NET_2_0
  572. get { return _transactionMode; }
  573. #endif
  574. set { _transactionMode = value; }
  575. }
  576. #if !NET_2_0
  577. //
  578. // This method is here just to remove the warning about "_transactionMode" not being
  579. // used. We probably will use it internally at some point.
  580. //
  581. internal int GetTransactionMode ()
  582. {
  583. return _transactionMode;
  584. }
  585. #endif
  586. #if NET_2_0
  587. [EditorBrowsable (EditorBrowsableState.Advanced)]
  588. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  589. [BrowsableAttribute (false)]
  590. public string UICulture {
  591. get { return Thread.CurrentThread.CurrentUICulture.Name; }
  592. set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
  593. }
  594. #else
  595. [EditorBrowsable (EditorBrowsableState.Never)]
  596. protected string UICulture {
  597. set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
  598. }
  599. #endif
  600. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  601. [Browsable (false)]
  602. public IPrincipal User {
  603. get { return Context.User; }
  604. }
  605. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  606. [Browsable (false)]
  607. public ValidatorCollection Validators {
  608. get {
  609. if (_validators == null)
  610. _validators = new ValidatorCollection ();
  611. return _validators;
  612. }
  613. }
  614. [MonoTODO ("Use this when encrypting/decrypting ViewState")]
  615. [Browsable (false)]
  616. public string ViewStateUserKey {
  617. get { return viewStateUserKey; }
  618. set { viewStateUserKey = value; }
  619. }
  620. [Browsable (false)]
  621. public override bool Visible {
  622. get { return base.Visible; }
  623. set { base.Visible = value; }
  624. }
  625. #endregion
  626. #region Methods
  627. #if NET_2_0
  628. CultureInfo GetPageCulture (string culture, CultureInfo deflt)
  629. {
  630. if (culture == null)
  631. return deflt;
  632. CultureInfo ret = null;
  633. if (culture.StartsWith ("auto", StringComparison.InvariantCultureIgnoreCase)) {
  634. #if TARGET_J2EE
  635. if (!Context.IsServletRequest)
  636. return deflt;
  637. #endif
  638. string[] languages = Request.UserLanguages;
  639. try {
  640. if (languages != null && languages.Length > 0)
  641. ret = CultureInfo.CreateSpecificCulture (languages[0]);
  642. } catch {
  643. }
  644. if (ret == null)
  645. ret = deflt;
  646. } else
  647. ret = CultureInfo.CreateSpecificCulture (culture);
  648. return ret;
  649. }
  650. #endif
  651. [EditorBrowsable (EditorBrowsableState.Never)]
  652. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  653. AsyncCallback cb,
  654. object extraData)
  655. {
  656. throw new NotImplementedException ();
  657. }
  658. [EditorBrowsable (EditorBrowsableState.Never)]
  659. protected void AspCompatEndProcessRequest (IAsyncResult result)
  660. {
  661. throw new NotImplementedException ();
  662. }
  663. [EditorBrowsable (EditorBrowsableState.Advanced)]
  664. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  665. {
  666. return new HtmlTextWriter (tw);
  667. }
  668. [EditorBrowsable (EditorBrowsableState.Never)]
  669. public void DesignerInitialize ()
  670. {
  671. InitRecursive (null);
  672. }
  673. [EditorBrowsable (EditorBrowsableState.Advanced)]
  674. protected virtual NameValueCollection DeterminePostBackMode ()
  675. {
  676. // if request was transfered from other page such Transfer
  677. if (_context.IsProcessingInclude)
  678. return null;
  679. HttpRequest req = Request;
  680. if (req == null)
  681. return null;
  682. NameValueCollection coll = null;
  683. if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture))
  684. coll = req.Form;
  685. else
  686. coll = req.QueryString;
  687. WebROCollection c = (WebROCollection) coll;
  688. allow_load = !c.GotID;
  689. if (allow_load)
  690. c.ID = GetTypeHashCode ();
  691. else
  692. allow_load = (c.ID == GetTypeHashCode ());
  693. if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
  694. return null;
  695. #if TARGET_J2EE
  696. if (getFacesContext () != null && _context.Handler != _context.CurrentHandler) {
  697. // check if it is PreviousPage
  698. string prevViewId = coll [PreviousPageID];
  699. if (!String.IsNullOrEmpty (prevViewId)) {
  700. string appPath = VirtualPathUtility.RemoveTrailingSlash (Request.ApplicationPath);
  701. prevViewId = prevViewId.Substring (appPath.Length);
  702. isCrossPagePostBack = String.Compare (prevViewId, getFacesContext ().getExternalContext ().getRequestPathInfo (), StringComparison.OrdinalIgnoreCase) == 0;
  703. }
  704. }
  705. #endif
  706. return coll;
  707. }
  708. #if NET_2_0
  709. public override Control FindControl (string id) {
  710. if (id == ID)
  711. return this;
  712. else
  713. return base.FindControl (id);
  714. }
  715. #endif
  716. Control FindControl (string id, bool decode) {
  717. #if TARGET_J2EE
  718. if (decode)
  719. id = DecodeNamespace (id);
  720. #endif
  721. return FindControl (id);
  722. }
  723. #if NET_2_0
  724. [Obsolete]
  725. #endif
  726. [EditorBrowsable (EditorBrowsableState.Advanced)]
  727. public string GetPostBackClientEvent (Control control, string argument)
  728. {
  729. return scriptManager.GetPostBackEventReference (control, argument);
  730. }
  731. #if NET_2_0
  732. [Obsolete]
  733. #endif
  734. [EditorBrowsable (EditorBrowsableState.Advanced)]
  735. public string GetPostBackClientHyperlink (Control control, string argument)
  736. {
  737. return scriptManager.GetPostBackClientHyperlink (control, argument);
  738. }
  739. #if NET_2_0
  740. [Obsolete]
  741. #endif
  742. [EditorBrowsable (EditorBrowsableState.Advanced)]
  743. public string GetPostBackEventReference (Control control)
  744. {
  745. return scriptManager.GetPostBackEventReference (control, "");
  746. }
  747. #if NET_2_0
  748. [Obsolete]
  749. #endif
  750. [EditorBrowsable (EditorBrowsableState.Advanced)]
  751. public string GetPostBackEventReference (Control control, string argument)
  752. {
  753. return scriptManager.GetPostBackEventReference (control, argument);
  754. }
  755. internal void RequiresPostBackScript ()
  756. {
  757. #if NET_2_0
  758. if (requiresPostBackScript)
  759. return;
  760. ClientScript.RegisterHiddenField (postEventSourceID, String.Empty);
  761. ClientScript.RegisterHiddenField (postEventArgumentID, String.Empty);
  762. #endif
  763. requiresPostBackScript = true;
  764. }
  765. [EditorBrowsable (EditorBrowsableState.Never)]
  766. public virtual int GetTypeHashCode ()
  767. {
  768. return 0;
  769. }
  770. #if NET_2_0
  771. [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
  772. protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
  773. {
  774. if (cacheSettings.Enabled)
  775. InitOutputCache(cacheSettings.Duration,
  776. cacheSettings.VaryByContentEncoding,
  777. cacheSettings.VaryByHeader,
  778. cacheSettings.VaryByCustom,
  779. cacheSettings.Location,
  780. cacheSettings.VaryByParam);
  781. }
  782. #endif
  783. #if NET_2_0
  784. [MonoTODO ("varyByContentEncoding is not currently used")]
  785. protected virtual
  786. #endif
  787. void InitOutputCache(int duration,
  788. string varyByContentEncoding,
  789. string varyByHeader,
  790. string varyByCustom,
  791. OutputCacheLocation location,
  792. string varyByParam)
  793. {
  794. HttpCachePolicy cache = Response.Cache;
  795. bool set_vary = false;
  796. HttpContext ctx = Context;
  797. DateTime timestamp = ctx != null ? ctx.Timestamp : DateTime.Now;
  798. switch (location) {
  799. case OutputCacheLocation.Any:
  800. cache.SetCacheability (HttpCacheability.Public);
  801. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  802. cache.SetLastModified (timestamp);
  803. set_vary = true;
  804. break;
  805. case OutputCacheLocation.Client:
  806. cache.SetCacheability (HttpCacheability.Private);
  807. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  808. cache.SetLastModified (timestamp);
  809. break;
  810. case OutputCacheLocation.Downstream:
  811. cache.SetCacheability (HttpCacheability.Public);
  812. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  813. cache.SetLastModified (timestamp);
  814. break;
  815. case OutputCacheLocation.Server:
  816. cache.SetCacheability (HttpCacheability.Server);
  817. set_vary = true;
  818. break;
  819. case OutputCacheLocation.None:
  820. break;
  821. }
  822. if (set_vary) {
  823. if (varyByCustom != null)
  824. cache.SetVaryByCustom (varyByCustom);
  825. if (varyByParam != null && varyByParam.Length > 0) {
  826. string[] prms = varyByParam.Split (';');
  827. foreach (string p in prms)
  828. cache.VaryByParams [p.Trim ()] = true;
  829. cache.VaryByParams.IgnoreParams = false;
  830. } else {
  831. cache.VaryByParams.IgnoreParams = true;
  832. }
  833. if (varyByHeader != null && varyByHeader.Length > 0) {
  834. string[] hdrs = varyByHeader.Split (';');
  835. foreach (string h in hdrs)
  836. cache.VaryByHeaders [h.Trim ()] = true;
  837. }
  838. }
  839. cache.Duration = duration;
  840. cache.SetExpires (timestamp.AddSeconds (duration));
  841. }
  842. [EditorBrowsable (EditorBrowsableState.Never)]
  843. protected virtual void InitOutputCache (int duration,
  844. string varyByHeader,
  845. string varyByCustom,
  846. OutputCacheLocation location,
  847. string varyByParam)
  848. {
  849. InitOutputCache (duration, null, varyByHeader, varyByCustom, location, varyByParam);
  850. }
  851. #if NET_2_0
  852. [Obsolete]
  853. #else
  854. [EditorBrowsable (EditorBrowsableState.Advanced)]
  855. #endif
  856. public bool IsClientScriptBlockRegistered (string key)
  857. {
  858. return scriptManager.IsClientScriptBlockRegistered (key);
  859. }
  860. #if NET_2_0
  861. [Obsolete]
  862. #else
  863. [EditorBrowsable (EditorBrowsableState.Advanced)]
  864. #endif
  865. public bool IsStartupScriptRegistered (string key)
  866. {
  867. return scriptManager.IsStartupScriptRegistered (key);
  868. }
  869. public string MapPath (string virtualPath)
  870. {
  871. return Request.MapPath (virtualPath);
  872. }
  873. #if NET_2_0
  874. protected internal override void Render (HtmlTextWriter writer) {
  875. if (MaintainScrollPositionOnPostBack) {
  876. ClientScript.RegisterWebFormClientScript ();
  877. ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
  878. ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
  879. string webForm = IsMultiForm ? theForm + "." : null;
  880. StringBuilder script = new StringBuilder ();
  881. script.AppendLine ("<script type=\"text/javascript\">");
  882. script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_START);
  883. script.AppendLine (theForm + ".oldSubmit = " + theForm + ".submit;");
  884. script.AppendLine (theForm + ".submit = function () { " + webForm + "WebForm_SaveScrollPositionSubmit(); }");
  885. script.AppendLine (theForm + ".oldOnSubmit = " + theForm + ".onsubmit;");
  886. script.AppendLine (theForm + ".onsubmit = function () { " + webForm + "WebForm_SaveScrollPositionOnSubmit(); }");
  887. if (IsPostBack) {
  888. script.AppendLine (theForm + ".oldOnLoad = window.onload;");
  889. script.AppendLine ("window.onload = function () { " + webForm + "WebForm_RestoreScrollPosition (); };");
  890. }
  891. script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_END);
  892. script.AppendLine ("</script>");
  893. ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
  894. }
  895. base.Render (writer);
  896. }
  897. #endif
  898. private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  899. {
  900. #if ONLY_1_1
  901. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
  902. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
  903. #endif
  904. writer.WriteLine ();
  905. ClientScriptManager.WriteBeginScriptBlock (writer);
  906. #if ONLY_1_1
  907. RenderClientScriptFormDeclaration (writer, formUniqueID);
  908. #endif
  909. if (IsMultiForm) {
  910. writer.WriteLine ("{0}._form = {0};", theForm);
  911. writer.Write (theForm + ".");
  912. } else {
  913. writer.WriteLine ("window._form = {0};", theForm);
  914. }
  915. writer.WriteLine ("__doPostBack = function (eventTarget, eventArgument) {");
  916. #if NET_2_0
  917. writer.WriteLine ("\tif(this._form.onsubmit && this._form.onsubmit() == false) return;");
  918. #else
  919. writer.WriteLine ("\tif(document.ValidatorOnSubmit && !ValidatorOnSubmit()) return;");
  920. #endif
  921. writer.WriteLine ("\tthis._form.{0}.value = eventTarget;", postEventSourceID);
  922. writer.WriteLine ("\tthis._form.{0}.value = eventArgument;", postEventArgumentID);
  923. writer.WriteLine ("\tthis._form.submit();");
  924. writer.WriteLine ("}");
  925. ClientScriptManager.WriteEndScriptBlock (writer);
  926. }
  927. void RenderClientScriptFormDeclaration (HtmlTextWriter writer, string formUniqueID)
  928. {
  929. writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
  930. writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
  931. writer.WriteLine ("\t{0}._instanceVariableName = '{0}';", theForm);
  932. #if TARGET_J2EE
  933. // TODO implement callback on portlet
  934. string serverUrl = Request.RawUrl;
  935. writer.WriteLine ("\t{0}.serverURL = {1};", theForm, ClientScriptManager.GetScriptLiteral (serverUrl));
  936. writer.WriteLine ("\twindow.TARGET_J2EE = true;");
  937. writer.WriteLine ("\twindow.IsMultiForm = {0};", IsMultiForm ? "true" : "false");
  938. #endif
  939. }
  940. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  941. {
  942. if (renderingForm)
  943. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  944. renderingForm = true;
  945. writer.WriteLine ();
  946. #if NET_2_0
  947. ClientScriptManager.WriteBeginScriptBlock (writer);
  948. RenderClientScriptFormDeclaration (writer, formUniqueID);
  949. ClientScriptManager.WriteEndScriptBlock (writer);
  950. #endif
  951. if (handleViewState)
  952. #if TARGET_J2EE
  953. if (getFacesContext () != null) {
  954. javax.faces.application.ViewHandler viewHandler = getFacesContext ().getApplication ().getViewHandler ();
  955. javax.faces.context.ResponseWriter oldFacesWriter = SetupResponseWriter (writer);
  956. try {
  957. viewHandler.writeState (getFacesContext ());
  958. }
  959. finally {
  960. getFacesContext ().setResponseWriter (oldFacesWriter);
  961. }
  962. }
  963. #endif
  964. scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
  965. scriptManager.WriteHiddenFields (writer);
  966. if (requiresPostBackScript) {
  967. RenderPostBackScript (writer, formUniqueID);
  968. postBackScriptRendered = true;
  969. }
  970. #if NET_2_0
  971. scriptManager.WriteWebFormClientScript (writer);
  972. #endif
  973. scriptManager.WriteClientScriptBlocks (writer);
  974. }
  975. internal IStateFormatter GetFormatter ()
  976. {
  977. return new ObjectStateFormatter (this);
  978. }
  979. internal string GetSavedViewState ()
  980. {
  981. return _savedViewState;
  982. }
  983. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  984. {
  985. #if NET_2_0
  986. scriptManager.SaveEventValidationState ();
  987. scriptManager.WriteExpandoAttributes (writer);
  988. #endif
  989. scriptManager.WriteHiddenFields (writer);
  990. if (!postBackScriptRendered && requiresPostBackScript)
  991. RenderPostBackScript (writer, formUniqueID);
  992. #if NET_2_0
  993. scriptManager.WriteWebFormClientScript (writer);
  994. #endif
  995. scriptManager.WriteArrayDeclares (writer);
  996. scriptManager.WriteStartupScriptBlocks (writer);
  997. renderingForm = false;
  998. postBackScriptRendered = false;
  999. }
  1000. private void ProcessPostData (NameValueCollection data, bool second)
  1001. {
  1002. NameValueCollection requestValues = _requestValueCollection == null ?
  1003. new NameValueCollection () :
  1004. _requestValueCollection;
  1005. if (data != null && data.Count > 0) {
  1006. Hashtable used = new Hashtable ();
  1007. foreach (string id in data.AllKeys){
  1008. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID ||
  1009. id == ClientScriptManager.EventStateFieldName)
  1010. continue;
  1011. if (used.ContainsKey (id))
  1012. continue;
  1013. used.Add (id, id);
  1014. Control ctrl = FindControl (id, true);
  1015. if (ctrl != null){
  1016. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  1017. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  1018. if (pbdh == null) {
  1019. if (pbeh != null)
  1020. RegisterRequiresRaiseEvent (pbeh);
  1021. continue;
  1022. }
  1023. if (pbdh.LoadPostData (id, requestValues) == true) {
  1024. if (requiresPostDataChanged == null)
  1025. requiresPostDataChanged = new ArrayList ();
  1026. requiresPostDataChanged.Add (pbdh);
  1027. }
  1028. if (_requiresPostBackCopy != null)
  1029. _requiresPostBackCopy.Remove (id);
  1030. } else if (!second) {
  1031. if (secondPostData == null)
  1032. secondPostData = new NameValueCollection ();
  1033. secondPostData.Add (id, data [id]);
  1034. }
  1035. }
  1036. }
  1037. ArrayList list1 = null;
  1038. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  1039. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  1040. foreach (string id in handlers) {
  1041. IPostBackDataHandler pbdh = FindControl (id, true) as IPostBackDataHandler;
  1042. if (pbdh != null) {
  1043. _requiresPostBackCopy.Remove (id);
  1044. if (pbdh.LoadPostData (id, requestValues)) {
  1045. if (requiresPostDataChanged == null)
  1046. requiresPostDataChanged = new ArrayList ();
  1047. requiresPostDataChanged.Add (pbdh);
  1048. }
  1049. } else if (!second) {
  1050. if (list1 == null)
  1051. list1 = new ArrayList ();
  1052. list1.Add (id);
  1053. }
  1054. }
  1055. }
  1056. _requiresPostBackCopy = second ? null : list1;
  1057. if (second)
  1058. secondPostData = null;
  1059. }
  1060. [EditorBrowsable (EditorBrowsableState.Never)]
  1061. #if NET_2_0
  1062. public virtual void ProcessRequest (HttpContext context)
  1063. #else
  1064. public void ProcessRequest (HttpContext context)
  1065. #endif
  1066. {
  1067. #if TARGET_J2EE
  1068. if (getFacesContext () != null)
  1069. EnterThread (context);
  1070. else
  1071. #endif
  1072. SetContext (context);
  1073. if (clientTarget != null)
  1074. Request.ClientTarget = clientTarget;
  1075. WireupAutomaticEvents ();
  1076. //-- Control execution lifecycle in the docs
  1077. // Save culture information because it can be modified in FrameworkInitialize()
  1078. _appCulture = Thread.CurrentThread.CurrentCulture;
  1079. _appUICulture = Thread.CurrentThread.CurrentUICulture;
  1080. FrameworkInitialize ();
  1081. context.ErrorPage = _errorPage;
  1082. try {
  1083. InternalProcessRequest ();
  1084. #if TARGET_J2EE
  1085. } catch (Exception ex) {
  1086. HandleException (ex);
  1087. throw;
  1088. }
  1089. finally {
  1090. if (getFacesContext () != null)
  1091. ExitThread ();
  1092. }
  1093. #else
  1094. } catch (ThreadAbortException) {
  1095. // Do nothing, just ignore it by now.
  1096. } catch (Exception e) {
  1097. ProcessException (e);
  1098. throw;
  1099. } finally {
  1100. ProcessUnload ();
  1101. }
  1102. #endif
  1103. }
  1104. void ProcessException (Exception ex) {
  1105. _context.AddError (ex); // OnError might access LastError
  1106. OnError (EventArgs.Empty);
  1107. _context.ClearError (ex);
  1108. // We want to remove that error, as we're rethrowing to stop
  1109. // further processing.
  1110. Trace.Warn ("Unhandled Exception", ex.ToString (), ex);
  1111. }
  1112. void ProcessUnload () {
  1113. try {
  1114. RenderTrace ();
  1115. UnloadRecursive (true);
  1116. } catch {}
  1117. #if TARGET_J2EE
  1118. if (getFacesContext () != null) {
  1119. if(IsCrossPagePostBack)
  1120. _context.Items [CrossPagePostBack] = this;
  1121. }
  1122. #endif
  1123. if (Thread.CurrentThread.CurrentCulture.Equals (_appCulture) == false)
  1124. Thread.CurrentThread.CurrentCulture = _appCulture;
  1125. if (Thread.CurrentThread.CurrentUICulture.Equals (_appUICulture) == false)
  1126. Thread.CurrentThread.CurrentUICulture = _appUICulture;
  1127. _appCulture = null;
  1128. _appUICulture = null;
  1129. }
  1130. #if NET_2_0
  1131. delegate void ProcessRequestDelegate (HttpContext context);
  1132. private sealed class DummyAsyncResult : IAsyncResult
  1133. {
  1134. readonly object state;
  1135. readonly WaitHandle asyncWaitHandle;
  1136. readonly bool completedSynchronously;
  1137. readonly bool isCompleted;
  1138. public DummyAsyncResult (bool isCompleted, bool completedSynchronously, object state)
  1139. {
  1140. this.isCompleted = isCompleted;
  1141. this.completedSynchronously = completedSynchronously;
  1142. this.state = state;
  1143. if (isCompleted) {
  1144. asyncWaitHandle = new ManualResetEvent (true);
  1145. }
  1146. else {
  1147. asyncWaitHandle = new ManualResetEvent (false);
  1148. }
  1149. }
  1150. #region IAsyncResult Members
  1151. public object AsyncState {
  1152. get { return state; }
  1153. }
  1154. public WaitHandle AsyncWaitHandle {
  1155. get { return asyncWaitHandle; }
  1156. }
  1157. public bool CompletedSynchronously {
  1158. get { return completedSynchronously; }
  1159. }
  1160. public bool IsCompleted {
  1161. get { return isCompleted; }
  1162. }
  1163. #endregion
  1164. }
  1165. protected IAsyncResult AsyncPageBeginProcessRequest (HttpContext context, AsyncCallback callback, object extraData)
  1166. {
  1167. ProcessRequest (context);
  1168. DummyAsyncResult asyncResult = new DummyAsyncResult (true, true, extraData);
  1169. if (callback != null) {
  1170. callback (asyncResult);
  1171. }
  1172. return asyncResult;
  1173. }
  1174. protected void AsyncPageEndProcessRequest (IAsyncResult result)
  1175. {
  1176. }
  1177. #endif
  1178. void InternalProcessRequest ()
  1179. {
  1180. _requestValueCollection = this.DeterminePostBackMode();
  1181. #if NET_2_0
  1182. // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
  1183. if (_requestValueCollection != null) {
  1184. if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
  1185. _doLoadPreviousPage = true;
  1186. }
  1187. else {
  1188. isCallback = _requestValueCollection [CallbackArgumentID] != null;
  1189. // LAMESPEC: on Callback IsPostBack is set to false, but true.
  1190. //isPostBack = !isCallback;
  1191. isPostBack = true;
  1192. }
  1193. string lastFocus = _requestValueCollection [LastFocusID];
  1194. if (!String.IsNullOrEmpty (lastFocus)) {
  1195. _focusedControlID = UniqueID2ClientID (lastFocus);
  1196. }
  1197. }
  1198. if (!isCrossPagePostBack) {
  1199. if (_context.PreviousHandler is Page) {
  1200. previousPage = (Page) _context.PreviousHandler;
  1201. }
  1202. }
  1203. Trace.Write ("aspx.page", "Begin PreInit");
  1204. OnPreInit (EventArgs.Empty);
  1205. Trace.Write ("aspx.page", "End PreInit");
  1206. InitializeTheme ();
  1207. ApplyMasterPage ();
  1208. #endif
  1209. Trace.Write ("aspx.page", "Begin Init");
  1210. InitRecursive (null);
  1211. Trace.Write ("aspx.page", "End Init");
  1212. #if NET_2_0
  1213. Trace.Write ("aspx.page", "Begin InitComplete");
  1214. OnInitComplete (EventArgs.Empty);
  1215. Trace.Write ("aspx.page", "End InitComplete");
  1216. #endif
  1217. renderingForm = false;
  1218. #if TARGET_J2EE
  1219. if (getFacesContext () != null)
  1220. if (IsPostBack || IsCallback)
  1221. return;
  1222. #endif
  1223. RestorePageState ();
  1224. ProcessPostData ();
  1225. ProcessRaiseEvents ();
  1226. if (ProcessLoadComplete ())
  1227. return;
  1228. #if TARGET_J2EE
  1229. if (getFacesContext () != null) {
  1230. getFacesContext ().renderResponse ();
  1231. return;
  1232. }
  1233. #endif
  1234. RenderPage ();
  1235. }
  1236. void RestorePageState () {
  1237. #if NET_2_0
  1238. if (IsPostBack || IsCallback) {
  1239. if (_requestValueCollection != null)
  1240. scriptManager.RestoreEventValidationState (
  1241. _requestValueCollection [ClientScriptManager.EventStateFieldName]);
  1242. #else
  1243. if (IsPostBack) {
  1244. #endif
  1245. Trace.Write ("aspx.page", "Begin LoadViewState");
  1246. LoadPageViewState ();
  1247. Trace.Write ("aspx.page", "End LoadViewState");
  1248. }
  1249. }
  1250. void ProcessPostData () {
  1251. #if NET_2_0
  1252. if (IsPostBack || IsCallback) {
  1253. #else
  1254. if (IsPostBack) {
  1255. #endif
  1256. Trace.Write ("aspx.page", "Begin ProcessPostData");
  1257. ProcessPostData (_requestValueCollection, false);
  1258. Trace.Write ("aspx.page", "End ProcessPostData");
  1259. }
  1260. ProcessLoad ();
  1261. #if NET_2_0
  1262. if (IsPostBack || IsCallback) {
  1263. #else
  1264. if (IsPostBack) {
  1265. #endif
  1266. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  1267. ProcessPostData (secondPostData, true);
  1268. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  1269. }
  1270. }
  1271. void ProcessLoad () {
  1272. #if NET_2_0
  1273. Trace.Write ("aspx.page", "Begin PreLoad");
  1274. OnPreLoad (EventArgs.Empty);
  1275. Trace.Write ("aspx.page", "End PreLoad");
  1276. #endif
  1277. Trace.Write ("aspx.page", "Begin Load");
  1278. LoadRecursive ();
  1279. Trace.Write ("aspx.page", "End Load");
  1280. }
  1281. void ProcessRaiseEvents () {
  1282. #if NET_2_0
  1283. if (IsPostBack || IsCallback) {
  1284. #else
  1285. if (IsPostBack) {
  1286. #endif
  1287. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  1288. RaiseChangedEvents ();
  1289. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  1290. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  1291. RaisePostBackEvents ();
  1292. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  1293. }
  1294. }
  1295. bool ProcessLoadComplete() {
  1296. #if NET_2_0
  1297. Trace.Write ("aspx.page", "Begin LoadComplete");
  1298. OnLoadComplete (EventArgs.Empty);
  1299. Trace.Write ("aspx.page", "End LoadComplete");
  1300. if (IsCrossPagePostBack)
  1301. return true;
  1302. if (IsCallback) {
  1303. #if TARGET_J2EE
  1304. if (getFacesContext () != null) {
  1305. _callbackTarget = GetCallbackTarget ();
  1306. ProcessRaiseCallbackEvent (_callbackTarget, ref _callbackEventError);
  1307. return true;
  1308. }
  1309. #endif
  1310. string result = ProcessCallbackData ();
  1311. HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);
  1312. callbackOutput.Write (result);
  1313. callbackOutput.Flush ();
  1314. return true;
  1315. }
  1316. #endif
  1317. Trace.Write ("aspx.page", "Begin PreRender");
  1318. PreRenderRecursiveInternal ();
  1319. Trace.Write ("aspx.page", "End PreRender");
  1320. #if NET_2_0
  1321. ExecuteRegisteredAsyncTasks ();
  1322. Trace.Write ("aspx.page", "Begin PreRenderComplete");
  1323. OnPreRenderComplete (EventArgs.Empty);
  1324. Trace.Write ("aspx.page", "End PreRenderComplete");
  1325. #endif
  1326. Trace.Write ("aspx.page", "Begin SaveViewState");
  1327. SavePageViewState ();
  1328. Trace.Write ("aspx.page", "End SaveViewState");
  1329. #if NET_2_0
  1330. Trace.Write ("aspx.page", "Begin SaveStateComplete");
  1331. OnSaveStateComplete (EventArgs.Empty);
  1332. Trace.Write ("aspx.page", "End SaveStateComplete");
  1333. #endif // NET_2_0
  1334. return false;
  1335. }
  1336. internal void RenderPage () {
  1337. #if NET_2_0
  1338. scriptManager.ResetEventValidationState ();
  1339. #endif
  1340. //--
  1341. Trace.Write ("aspx.page", "Begin Render");
  1342. HtmlTextWriter output = new HtmlTextWriter (Response.Output);
  1343. #if TARGET_J2EE
  1344. if (getFacesContext () != null)
  1345. SetupResponseWriter (output);
  1346. #endif
  1347. RenderControl (output);
  1348. Trace.Write ("aspx.page", "End Render");
  1349. }
  1350. void SetContext (HttpContext context) {
  1351. _context = context;
  1352. _application = context.Application;
  1353. _response = context.Response;
  1354. _request = context.Request;
  1355. _cache = context.Cache;
  1356. }
  1357. private void RenderTrace ()
  1358. {
  1359. TraceManager traceManager = HttpRuntime.TraceManager;
  1360. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  1361. return;
  1362. Trace.SaveData ();
  1363. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  1364. return;
  1365. if (!traceManager.LocalOnly || Context.Request.IsLocal) {
  1366. HtmlTextWriter output = new HtmlTextWriter (Response.Output);
  1367. Trace.Render (output);
  1368. }
  1369. }
  1370. #if NET_2_0
  1371. bool CheckForValidationSupport (Control targetControl)
  1372. {
  1373. if (targetControl == null)
  1374. return false;
  1375. Type type = targetControl.GetType ();
  1376. object[] attributes = type.GetCustomAttributes (false);
  1377. foreach (object attr in attributes)
  1378. if (attr is SupportsEventValidationAttribute)
  1379. return true;
  1380. return false;
  1381. }
  1382. #endif
  1383. void RaisePostBackEvents ()
  1384. {
  1385. #if NET_2_0
  1386. Control targetControl;
  1387. #endif
  1388. if (requiresRaiseEvent != null) {
  1389. RaisePostBackEvent (requiresRaiseEvent, null);
  1390. return;
  1391. }
  1392. NameValueCollection postdata = _requestValueCollection;
  1393. if (postdata == null)
  1394. return;
  1395. string eventTarget = postdata [postEventSourceID];
  1396. if (eventTarget == null || eventTarget.Length == 0) {
  1397. Validate ();
  1398. return;
  1399. }
  1400. #if NET_2_0
  1401. targetControl = FindControl (eventTarget, true);
  1402. IPostBackEventHandler target = targetControl as IPostBackEventHandler;
  1403. #else
  1404. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  1405. #endif
  1406. if (target == null)
  1407. return;
  1408. string eventArgument = postdata [postEventArgumentID];
  1409. RaisePostBackEvent (target, eventArgument);
  1410. }
  1411. internal void RaiseChangedEvents ()
  1412. {
  1413. if (requiresPostDataChanged == null)
  1414. return;
  1415. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1416. ipdh.RaisePostDataChangedEvent ();
  1417. requiresPostDataChanged = null;
  1418. }
  1419. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1420. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1421. {
  1422. #if NET_2_0
  1423. Control targetControl = sourceControl as Control;
  1424. if (targetControl != null && CheckForValidationSupport (targetControl))
  1425. scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
  1426. #endif
  1427. sourceControl.RaisePostBackEvent (eventArgument);
  1428. }
  1429. #if NET_2_0
  1430. [Obsolete]
  1431. #endif
  1432. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1433. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1434. {
  1435. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1436. }
  1437. #if NET_2_0
  1438. [Obsolete]
  1439. #endif
  1440. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1441. public virtual void RegisterClientScriptBlock (string key, string script)
  1442. {
  1443. scriptManager.RegisterClientScriptBlock (key, script);
  1444. }
  1445. #if NET_2_0
  1446. [Obsolete]
  1447. #endif
  1448. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1449. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1450. {
  1451. scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  1452. }
  1453. [MonoTODO("Not implemented, Used in HtmlForm")]
  1454. internal void RegisterClientScriptFile (string a, string b, string c)
  1455. {
  1456. throw new NotImplementedException ();
  1457. }
  1458. #if NET_2_0
  1459. [Obsolete]
  1460. #endif
  1461. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1462. public void RegisterOnSubmitStatement (string key, string script)
  1463. {
  1464. scriptManager.RegisterOnSubmitStatement (key, script);
  1465. }
  1466. internal string GetSubmitStatements ()
  1467. {
  1468. return scriptManager.WriteSubmitStatements ();
  1469. }
  1470. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1471. public void RegisterRequiresPostBack (Control control)
  1472. {
  1473. #if NET_2_0
  1474. if (!(control is IPostBackDataHandler))
  1475. throw new HttpException ("The control to register does not implement the IPostBackDataHandler interface.");
  1476. #endif
  1477. if (_requiresPostBack == null)
  1478. _requiresPostBack = new ArrayList ();
  1479. if (_requiresPostBack.Contains (control.UniqueID))
  1480. return;
  1481. _requiresPostBack.Add (control.UniqueID);
  1482. }
  1483. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1484. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  1485. {
  1486. requiresRaiseEvent = control;
  1487. }
  1488. #if NET_2_0
  1489. [Obsolete]
  1490. #endif
  1491. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1492. public virtual void RegisterStartupScript (string key, string script)
  1493. {
  1494. scriptManager.RegisterStartupScript (key, script);
  1495. }
  1496. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1497. public void RegisterViewStateHandler ()
  1498. {
  1499. handleViewState = true;
  1500. }
  1501. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1502. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  1503. {
  1504. PageStatePersister persister = this.PageStatePersister;
  1505. if (persister == null)
  1506. return;
  1507. Pair pair = viewState as Pair;
  1508. if (pair != null) {
  1509. persister.ViewState = pair.First;
  1510. persister.ControlState = pair.Second;
  1511. } else
  1512. persister.ViewState = viewState;
  1513. persister.Save ();
  1514. }
  1515. internal string RawViewState {
  1516. get {
  1517. NameValueCollection postdata = _requestValueCollection;
  1518. string view_state;
  1519. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  1520. return null;
  1521. if (view_state == "")
  1522. return null;
  1523. return view_state;
  1524. }
  1525. set { _savedViewState = value; }
  1526. }
  1527. #if NET_2_0
  1528. protected virtual
  1529. #else
  1530. internal
  1531. #endif
  1532. PageStatePersister PageStatePersister {
  1533. get {
  1534. if (page_state_persister == null)
  1535. #if TARGET_J2EE
  1536. if (getFacesContext () != null)
  1537. return new FacesPageStatePersister (this);
  1538. else
  1539. #endif
  1540. page_state_persister = new HiddenFieldPageStatePersister (this);
  1541. return page_state_persister;
  1542. }
  1543. }
  1544. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1545. protected virtual object LoadPageStateFromPersistenceMedium ()
  1546. {
  1547. PageStatePersister persister = this.PageStatePersister;
  1548. if (persister == null)
  1549. return null;
  1550. persister.Load ();
  1551. return new Pair (persister.ViewState, persister.ControlState);
  1552. }
  1553. internal void LoadPageViewState()
  1554. {
  1555. Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
  1556. if (sState != null) {
  1557. if (allow_load) {
  1558. #if NET_2_0
  1559. LoadPageControlState (sState.Second);
  1560. #endif
  1561. Pair vsr = sState.First as Pair;
  1562. if (vsr != null) {
  1563. LoadViewStateRecursive (vsr.First);
  1564. _requiresPostBackCopy = vsr.Second as ArrayList;
  1565. }
  1566. }
  1567. }
  1568. }
  1569. internal void SavePageViewState ()
  1570. {
  1571. if (!handleViewState)
  1572. return;
  1573. #if NET_2_0
  1574. object controlState = SavePageControlState ();
  1575. #endif
  1576. object viewState = SaveViewStateRecursive ();
  1577. object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
  1578. Pair vsr = null;
  1579. if (viewState != null || reqPostback != null)
  1580. vsr = new Pair (viewState, reqPostback);
  1581. Pair pair = new Pair ();
  1582. pair.First = vsr;
  1583. #if NET_2_0
  1584. pair.Second = controlState;
  1585. #else
  1586. pair.Second = null;
  1587. #endif
  1588. if (pair.First == null && pair.Second == null)
  1589. SavePageStateToPersistenceMedium (null);
  1590. else
  1591. SavePageStateToPersistenceMedium (pair);
  1592. }
  1593. public virtual void Validate ()
  1594. {
  1595. is_validated = true;
  1596. ValidateCollection (_validators);
  1597. }
  1598. #if NET_2_0
  1599. internal bool AreValidatorsUplevel () {
  1600. return AreValidatorsUplevel (String.Empty);
  1601. }
  1602. internal bool AreValidatorsUplevel (string valGroup)
  1603. #else
  1604. internal virtual bool AreValidatorsUplevel ()
  1605. #endif
  1606. {
  1607. bool uplevel = false;
  1608. foreach (IValidator v in Validators) {
  1609. BaseValidator bv = v as BaseValidator;
  1610. if (bv == null) continue;
  1611. #if NET_2_0
  1612. if (valGroup != bv.ValidationGroup)
  1613. continue;
  1614. #endif
  1615. if (bv.GetRenderUplevel()) {
  1616. uplevel = true;
  1617. break;
  1618. }
  1619. }
  1620. return uplevel;
  1621. }
  1622. bool ValidateCollection (ValidatorCollection validators)
  1623. {
  1624. #if NET_2_0
  1625. if (!_eventValidation)
  1626. return true;
  1627. #endif
  1628. if (validators == null || validators.Count == 0)
  1629. return true;
  1630. bool all_valid = true;
  1631. foreach (IValidator v in validators){
  1632. v.Validate ();
  1633. if (v.IsValid == false)
  1634. all_valid = false;
  1635. }
  1636. return all_valid;
  1637. }
  1638. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1639. public virtual void VerifyRenderingInServerForm (Control control)
  1640. {
  1641. if (Context == null)
  1642. return;
  1643. #if NET_2_0
  1644. if (IsCallback)
  1645. return;
  1646. #endif
  1647. if (!renderingForm)
  1648. throw new HttpException ("Control '" +
  1649. control.ClientID +
  1650. "' of type '" +
  1651. control.GetType ().Name +
  1652. "' must be placed inside a form tag with runat=server.");
  1653. }
  1654. protected override void FrameworkInitialize ()
  1655. {
  1656. base.FrameworkInitialize ();
  1657. #if NET_2_0
  1658. InitializeStyleSheet ();
  1659. #endif
  1660. }
  1661. #endregion
  1662. #if NET_2_0
  1663. public
  1664. #else
  1665. internal
  1666. #endif
  1667. ClientScriptManager ClientScript {
  1668. get { return scriptManager; }
  1669. }
  1670. #if NET_2_0
  1671. static readonly object InitCompleteEvent = new object ();
  1672. static readonly object LoadCompleteEvent = new object ();
  1673. static readonly object PreInitEvent = new object ();
  1674. static readonly object PreLoadEvent = new object ();
  1675. static readonly object PreRenderCompleteEvent = new object ();
  1676. static readonly object SaveStateCompleteEvent = new object ();
  1677. int event_mask;
  1678. const int initcomplete_mask = 1;
  1679. const int loadcomplete_mask = 1 << 1;
  1680. const int preinit_mask = 1 << 2;
  1681. const int preload_mask = 1 << 3;
  1682. const int prerendercomplete_mask = 1 << 4;
  1683. const int savestatecomplete_mask = 1 << 5;
  1684. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1685. public event EventHandler InitComplete {
  1686. add {
  1687. event_mask |= initcomplete_mask;
  1688. Events.AddHandler (InitCompleteEvent, value);
  1689. }
  1690. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1691. }
  1692. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1693. public event EventHandler LoadComplete {
  1694. add {
  1695. event_mask |= loadcomplete_mask;
  1696. Events.AddHandler (LoadCompleteEvent, value);
  1697. }
  1698. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1699. }
  1700. public event EventHandler PreInit {
  1701. add {
  1702. event_mask |= preinit_mask;
  1703. Events.AddHandler (PreInitEvent, value);
  1704. }
  1705. remove { Events.RemoveHandler (PreInitEvent, value); }
  1706. }
  1707. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1708. public event EventHandler PreLoad {
  1709. add {
  1710. event_mask |= preload_mask;
  1711. Events.AddHandler (PreLoadEvent, value);
  1712. }
  1713. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1714. }
  1715. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1716. public event EventHandler PreRenderComplete {
  1717. add {
  1718. event_mask |= prerendercomplete_mask;
  1719. Events.AddHandler (PreRenderCompleteEvent, value);
  1720. }
  1721. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1722. }
  1723. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1724. public event EventHandler SaveStateComplete {
  1725. add {
  1726. event_mask |= savestatecomplete_mask;
  1727. Events.AddHandler (SaveStateCompleteEvent, value);
  1728. }
  1729. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1730. }
  1731. protected virtual void OnInitComplete (EventArgs e)
  1732. {
  1733. if ((event_mask & initcomplete_mask) != 0) {
  1734. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1735. if (eh != null) eh (this, e);
  1736. }
  1737. }
  1738. protected virtual void OnLoadComplete (EventArgs e)
  1739. {
  1740. if ((event_mask & loadcomplete_mask) != 0) {
  1741. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1742. if (eh != null) eh (this, e);
  1743. }
  1744. }
  1745. protected virtual void OnPreInit (EventArgs e)
  1746. {
  1747. if ((event_mask & preinit_mask) != 0) {
  1748. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1749. if (eh != null) eh (this, e);
  1750. }
  1751. }
  1752. protected virtual void OnPreLoad (EventArgs e)
  1753. {
  1754. if ((event_mask & preload_mask) != 0) {
  1755. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1756. if (eh != null) eh (this, e);
  1757. }
  1758. }
  1759. protected virtual void OnPreRenderComplete (EventArgs e)
  1760. {
  1761. if ((event_mask & prerendercomplete_mask) != 0) {
  1762. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1763. if (eh != null) eh (this, e);
  1764. }
  1765. if (Form == null)
  1766. return;
  1767. if (!Form.DetermineRenderUplevel ())
  1768. return;
  1769. string defaultButtonId = Form.DefaultButton;
  1770. /* figure out if we have some control we're going to focus */
  1771. if (String.IsNullOrEmpty (_focusedControlID)) {
  1772. _focusedControlID = Form.DefaultFocus;
  1773. if (String.IsNullOrEmpty (_focusedControlID))
  1774. _focusedControlID = defaultButtonId;
  1775. }
  1776. if (!String.IsNullOrEmpty (_focusedControlID)) {
  1777. ClientScript.RegisterWebFormClientScript ();
  1778. ClientScript.RegisterStartupScript (
  1779. "HtmlForm-DefaultButton-StartupScript",
  1780. "<script type=\"text/javascript\">\n" + ClientScriptManager.SCRIPT_BLOCK_START +
  1781. "\nWebForm_AutoFocus('" + _focusedControlID + "');\n" + ClientScriptManager.SCRIPT_BLOCK_END +
  1782. "\n</script>\n");
  1783. }
  1784. if (Form.SubmitDisabledControls && _hasEnabledControlArray) {
  1785. ClientScript.RegisterWebFormClientScript ();
  1786. ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
  1787. "WebForm_ReEnableControls(this);");
  1788. }
  1789. }
  1790. internal void RegisterEnabledControl (Control control)
  1791. {
  1792. if (Form == null || !Page.Form.SubmitDisabledControls || !Page.Form.DetermineRenderUplevel ())
  1793. return;
  1794. _hasEnabledControlArray = true;
  1795. Page.ClientScript.RegisterArrayDeclaration (EnabledControlArrayID, String.Concat ("'", control.ClientID, "'"));
  1796. }
  1797. protected virtual void OnSaveStateComplete (EventArgs e)
  1798. {
  1799. if ((event_mask & savestatecomplete_mask) != 0) {
  1800. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1801. if (eh != null) eh (this, e);
  1802. }
  1803. }
  1804. public HtmlForm Form {
  1805. get { return _form; }
  1806. }
  1807. internal void RegisterForm (HtmlForm form)
  1808. {
  1809. _form = form;
  1810. }
  1811. [BrowsableAttribute (false)]
  1812. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1813. public Page PreviousPage {
  1814. get {
  1815. if (_doLoadPreviousPage) {
  1816. _doLoadPreviousPage = false;
  1817. LoadPreviousPageReference ();
  1818. }
  1819. return previousPage;
  1820. }
  1821. }
  1822. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1823. [BrowsableAttribute (false)]
  1824. public bool IsCallback {
  1825. get { return isCallback; }
  1826. }
  1827. [BrowsableAttribute (false)]
  1828. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1829. public bool IsCrossPagePostBack {
  1830. get { return isCrossPagePostBack; }
  1831. }
  1832. public new virtual char IdSeparator {
  1833. get {
  1834. //TODO: why override?
  1835. return base.IdSeparator;
  1836. }
  1837. }
  1838. string ProcessCallbackData ()
  1839. {
  1840. ICallbackEventHandler target = GetCallbackTarget ();
  1841. string callbackEventError = String.Empty;
  1842. ProcessRaiseCallbackEvent (target, ref callbackEventError);
  1843. return ProcessGetCallbackResult (target, callbackEventError);
  1844. }
  1845. ICallbackEventHandler GetCallbackTarget () {
  1846. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1847. if (callbackTarget == null || callbackTarget.Length == 0)
  1848. throw new HttpException ("Callback target not provided.");
  1849. Control targetControl = FindControl (callbackTarget, true);
  1850. ICallbackEventHandler target = targetControl as ICallbackEventHandler;
  1851. if (target == null)
  1852. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1853. return target;
  1854. }
  1855. void ProcessRaiseCallbackEvent (ICallbackEventHandler target, ref string callbackEventError) {
  1856. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1857. try {
  1858. target.RaiseCallbackEvent (callbackArgument);
  1859. } catch (Exception ex) {
  1860. callbackEventError = String.Concat ("e", ex.Message);
  1861. }
  1862. }
  1863. string ProcessGetCallbackResult (ICallbackEventHandler target, string callbackEventError) {
  1864. string callBackResult;
  1865. try {
  1866. callBackResult = target.GetCallbackResult ();
  1867. } catch (Exception ex) {
  1868. return String.Concat ("e", ex.Message);
  1869. }
  1870. string eventValidation = ClientScript.GetEventValidationStateFormatted ();
  1871. return callbackEventError + (eventValidation == null ? "0" : eventValidation.Length.ToString ()) + "|" +
  1872. eventValidation + callBackResult;
  1873. }
  1874. [BrowsableAttribute (false)]
  1875. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1876. public HtmlHead Header {
  1877. get { return htmlHeader; }
  1878. }
  1879. internal void SetHeader (HtmlHead header)
  1880. {
  1881. htmlHeader = header;
  1882. if (_title != null) {
  1883. htmlHeader.Title = _title;
  1884. _title = null;
  1885. }
  1886. }
  1887. protected bool AsyncMode {
  1888. get { return asyncMode; }
  1889. set { asyncMode = value; }
  1890. }
  1891. public TimeSpan AsyncTimeout {
  1892. get { return asyncTimeout; }
  1893. set { asyncTimeout = value; }
  1894. }
  1895. public bool IsAsync {
  1896. get { return AsyncMode; }
  1897. }
  1898. [MonoTODO ("Not Implemented")]
  1899. protected internal virtual string UniqueFilePathSuffix {
  1900. get {
  1901. throw new NotImplementedException ();
  1902. }
  1903. }
  1904. [MonoTODO ("Not Implemented")]
  1905. public int MaxPageStateFieldLength {
  1906. get {
  1907. throw new NotImplementedException ();
  1908. }
  1909. set {
  1910. throw new NotImplementedException ();
  1911. }
  1912. }
  1913. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
  1914. {
  1915. AddOnPreRenderCompleteAsync (beginHandler, endHandler, null);
  1916. }
  1917. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
  1918. {
  1919. if (!IsAsync) {
  1920. throw new InvalidOperationException ("AddOnPreRenderCompleteAsync called and Page.IsAsync == false");
  1921. }
  1922. if (IsPrerendered) {
  1923. throw new InvalidOperationException ("AddOnPreRenderCompleteAsync can only be called before and during PreRender.");
  1924. }
  1925. if (beginHandler == null) {
  1926. throw new ArgumentNullException ("beginHandler");
  1927. }
  1928. if (endHandler == null) {
  1929. throw new ArgumentNullException ("endHandler");
  1930. }
  1931. RegisterAsyncTask (new PageAsyncTask (beginHandler, endHandler, null, state, false));
  1932. }
  1933. private List<PageAsyncTask> ParallelTasks {
  1934. get {
  1935. if (parallelTasks == null) {
  1936. parallelTasks = new List<PageAsyncTask>();
  1937. }
  1938. return parallelTasks;
  1939. }
  1940. }
  1941. private List<PageAsyncTask> SerialTasks {
  1942. get {
  1943. if (serialTasks == null) {
  1944. serialTasks = new List<PageAsyncTask> ();
  1945. }
  1946. return serialTasks;
  1947. }
  1948. }
  1949. public void RegisterAsyncTask (PageAsyncTask task)
  1950. {
  1951. if (task == null) {
  1952. throw new ArgumentNullException ("task");
  1953. }
  1954. if (task.ExecuteInParallel) {
  1955. ParallelTasks.Add (task);
  1956. }
  1957. else {
  1958. SerialTasks.Add (task);
  1959. }
  1960. }
  1961. public void ExecuteRegisteredAsyncTasks ()
  1962. {
  1963. if ((parallelTasks == null || parallelTasks.Count == 0) &&
  1964. (serialTasks == null || serialTasks.Count == 0)){
  1965. return;
  1966. }
  1967. if (parallelTasks != null) {
  1968. DateTime startExecution = DateTime.Now;
  1969. List<PageAsyncTask> localParallelTasks = parallelTasks;
  1970. parallelTasks = null; // Shouldn't execute tasks twice
  1971. List<IAsyncResult> asyncResults = new List<IAsyncResult>();
  1972. foreach (PageAsyncTask parallelTask in localParallelTasks) {
  1973. IAsyncResult result = parallelTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), parallelTask.State);
  1974. if (result.CompletedSynchronously) {
  1975. parallelTask.EndHandler (result);
  1976. }
  1977. else {
  1978. asyncResults.Add (result);
  1979. }
  1980. }
  1981. if (asyncResults.Count > 0) {
  1982. #if TARGET_JVM
  1983. TimeSpan timeout = AsyncTimeout;
  1984. long t1 = DateTime.Now.Ticks;
  1985. bool signalled = true;
  1986. for (int i = 0; i < asyncResults.Count; i++) {
  1987. if (asyncResults [i].IsCompleted)
  1988. continue;
  1989. if (signalled)
  1990. signalled = asyncResults [i].AsyncWaitHandle.WaitOne (timeout, false);
  1991. if (signalled) {
  1992. long t2 = DateTime.Now.Ticks;
  1993. timeout = AsyncTimeout - TimeSpan.FromTicks (t2 - t1);
  1994. if (timeout.Ticks <= 0)
  1995. signalled = false;
  1996. }
  1997. else {
  1998. localParallelTasks [i].TimeoutHandler (asyncResults [i]);
  1999. }
  2000. }
  2001. #else
  2002. WaitHandle [] waitArray = new WaitHandle [asyncResults.Count];
  2003. int i = 0;
  2004. for (i = 0; i < asyncResults.Count; i++) {
  2005. waitArray [i] = asyncResults [i].AsyncWaitHandle;
  2006. }
  2007. bool allSignalled = WaitHandle.WaitAll (waitArray, AsyncTimeout, false);
  2008. if (!allSignalled) {
  2009. for (i = 0; i < asyncResults.Count; i++) {
  2010. if (!asyncResults [i].IsCompleted) {
  2011. localParallelTasks [i].TimeoutHandler (asyncResults [i]);
  2012. }
  2013. }
  2014. }
  2015. #endif
  2016. }
  2017. DateTime endWait = DateTime.Now;
  2018. TimeSpan elapsed = endWait - startExecution;
  2019. if (elapsed <= AsyncTimeout) {
  2020. AsyncTimeout -= elapsed;
  2021. }
  2022. else {
  2023. AsyncTimeout = TimeSpan.FromTicks(0);
  2024. }
  2025. }
  2026. if (serialTasks != null) {
  2027. List<PageAsyncTask> localSerialTasks = serialTasks;
  2028. serialTasks = null; // Shouldn't execute tasks twice
  2029. foreach (PageAsyncTask serialTask in localSerialTasks) {
  2030. DateTime startExecution = DateTime.Now;
  2031. IAsyncResult result = serialTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), serialTask);
  2032. if (result.CompletedSynchronously) {
  2033. serialTask.EndHandler (result);
  2034. }
  2035. else {
  2036. bool done = result.AsyncWaitHandle.WaitOne (AsyncTimeout, false);
  2037. if (!done && !result.IsCompleted) {
  2038. serialTask.TimeoutHandler (result);
  2039. }
  2040. }
  2041. DateTime endWait = DateTime.Now;
  2042. TimeSpan elapsed = endWait - startExecution;
  2043. if (elapsed <= AsyncTimeout) {
  2044. AsyncTimeout -= elapsed;
  2045. }
  2046. else {
  2047. AsyncTimeout = TimeSpan.FromTicks (0);
  2048. }
  2049. }
  2050. }
  2051. AsyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
  2052. }
  2053. void EndAsyncTaskCallback (IAsyncResult result)
  2054. {
  2055. PageAsyncTask task = (PageAsyncTask)result.AsyncState;
  2056. task.EndHandler (result);
  2057. }
  2058. public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
  2059. {
  2060. Type htmlTextWriterType = typeof (HtmlTextWriter);
  2061. if (!htmlTextWriterType.IsAssignableFrom (writerType)) {
  2062. throw new HttpException (String.Format ("Type '{0}' cannot be assigned to HtmlTextWriter", writerType.FullName));
  2063. }
  2064. ConstructorInfo constructor = writerType.GetConstructor (new Type [] { typeof (TextWriter) });
  2065. if (constructor == null) {
  2066. throw new HttpException (String.Format ("Type '{0}' does not have a consturctor that takes a TextWriter as parameter", writerType.FullName));
  2067. }
  2068. return (HtmlTextWriter) Activator.CreateInstance(writerType, tw);
  2069. }
  2070. public ViewStateEncryptionMode ViewStateEncryptionMode {
  2071. get { return viewStateEncryptionMode; }
  2072. set { viewStateEncryptionMode = value; }
  2073. }
  2074. public void RegisterRequiresViewStateEncryption ()
  2075. {
  2076. controlRegisteredForViewStateEncryption = true;
  2077. }
  2078. private static byte [] AES_IV = null;
  2079. private static byte [] TripleDES_IV = null;
  2080. private static object locker = new object ();
  2081. private static bool isEncryptionInitialized = false;
  2082. private static void InitializeEncryption ()
  2083. {
  2084. if (isEncryptionInitialized) {
  2085. return;
  2086. }
  2087. lock (locker) {
  2088. if (isEncryptionInitialized) {
  2089. return;
  2090. }
  2091. string iv_string = "0BA48A9E-736D-40f8-954B-B2F62241F282";
  2092. AES_IV = new byte [16];
  2093. TripleDES_IV = new byte [8];
  2094. int i;
  2095. for (i = 0; i < AES_IV.Length; i++) {
  2096. AES_IV [i] = (byte) iv_string [i];
  2097. }
  2098. for (i = 0; i < TripleDES_IV.Length; i++) {
  2099. TripleDES_IV [i] = (byte) iv_string [i];
  2100. }
  2101. isEncryptionInitialized = true;
  2102. }
  2103. }
  2104. internal ICryptoTransform GetCryptoTransform (CryptoStreamMode cryptoStreamMode)
  2105. {
  2106. ICryptoTransform transform = null;
  2107. MachineKeySection config = (MachineKeySection) WebConfigurationManager.GetSection (machineKeyConfigPath);
  2108. byte [] vk = MachineKeySectionUtils.ValidationKeyBytes (config);
  2109. switch (config.Validation) {
  2110. case MachineKeyValidation.SHA1:
  2111. transform = SHA1.Create ();
  2112. break;
  2113. case MachineKeyValidation.MD5:
  2114. transform = MD5.Create ();
  2115. break;
  2116. case MachineKeyValidation.AES:
  2117. if (cryptoStreamMode == CryptoStreamMode.Read){
  2118. transform = Rijndael.Create().CreateDecryptor(vk, AES_IV);
  2119. } else {
  2120. transform = Rijndael.Create().CreateEncryptor(vk, AES_IV);
  2121. }
  2122. break;
  2123. case MachineKeyValidation.TripleDES:
  2124. if (cryptoStreamMode == CryptoStreamMode.Read){
  2125. transform = TripleDES.Create().CreateDecryptor(vk, TripleDES_IV);
  2126. } else {
  2127. transform = TripleDES.Create().CreateEncryptor(vk, TripleDES_IV);
  2128. }
  2129. break;
  2130. }
  2131. return transform;
  2132. }
  2133. internal bool NeedViewStateEncryption {
  2134. get {
  2135. return (ViewStateEncryptionMode == ViewStateEncryptionMode.Always ||
  2136. (ViewStateEncryptionMode == ViewStateEncryptionMode.Auto &&
  2137. controlRegisteredForViewStateEncryption));
  2138. }
  2139. }
  2140. void ApplyMasterPage ()
  2141. {
  2142. if (masterPageFile != null && masterPageFile.Length > 0) {
  2143. ArrayList appliedMasterPageFiles = new ArrayList ();
  2144. if (Master != null) {
  2145. MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
  2146. Master.Page = this;
  2147. Controls.Clear ();
  2148. Controls.Add (Master);
  2149. }
  2150. }
  2151. }
  2152. [DefaultValueAttribute ("")]
  2153. public virtual string MasterPageFile {
  2154. get { return masterPageFile; }
  2155. set {
  2156. masterPageFile = value;
  2157. masterPage = null;
  2158. }
  2159. }
  2160. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  2161. [BrowsableAttribute (false)]
  2162. public MasterPage Master {
  2163. get {
  2164. if (Context == null || String.IsNullOrEmpty (masterPageFile))
  2165. return null;
  2166. if (masterPage == null)
  2167. masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
  2168. return masterPage;
  2169. }
  2170. }
  2171. public void SetFocus (string clientID)
  2172. {
  2173. if (String.IsNullOrEmpty (clientID))
  2174. throw new ArgumentNullException ("control");
  2175. if (IsPrerendered)
  2176. throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
  2177. if(Form==null)
  2178. throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
  2179. _focusedControlID = clientID;
  2180. }
  2181. public void SetFocus (Control control)
  2182. {
  2183. if (control == null)
  2184. throw new ArgumentNullException ("control");
  2185. SetFocus (control.ClientID);
  2186. }
  2187. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2188. public void RegisterRequiresControlState (Control control)
  2189. {
  2190. if (control == null)
  2191. throw new ArgumentNullException ("control");
  2192. if (RequiresControlState (control))
  2193. return;
  2194. if (requireStateControls == null)
  2195. requireStateControls = new ArrayList ();
  2196. int n = requireStateControls.Add (control);
  2197. if (_savedControlState == null || n >= _savedControlState.Length)
  2198. return;
  2199. for (Control parent = control.Parent; parent != null; parent = parent.Parent)
  2200. if (parent.IsChildControlStateCleared)
  2201. return;
  2202. object state = _savedControlState [n];
  2203. if (state != null)
  2204. control.LoadControlState (state);
  2205. }
  2206. public bool RequiresControlState (Control control)
  2207. {
  2208. if (requireStateControls == null) return false;
  2209. return requireStateControls.Contains (control);
  2210. }
  2211. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2212. public void UnregisterRequiresControlState (Control control)
  2213. {
  2214. if (requireStateControls != null)
  2215. requireStateControls.Remove (control);
  2216. }
  2217. public ValidatorCollection GetValidators (string validationGroup)
  2218. {
  2219. if (validationGroup == String.Empty)
  2220. validationGroup = null;
  2221. ValidatorCollection col = new ValidatorCollection ();
  2222. if (_validators == null)
  2223. return col;
  2224. foreach (IValidator v in _validators)
  2225. if (BelongsToGroup(v, validationGroup))
  2226. col.Add(v);
  2227. return col;
  2228. }
  2229. bool BelongsToGroup(IValidator v, string validationGroup) {
  2230. BaseValidator validator = v as BaseValidator;
  2231. if (validationGroup == null)
  2232. return validator == null || String.IsNullOrEmpty (validator.ValidationGroup);
  2233. else
  2234. return validator != null && validator.ValidationGroup == validationGroup;
  2235. }
  2236. public virtual void Validate (string validationGroup)
  2237. {
  2238. is_validated = true;
  2239. ValidateCollection (GetValidators (validationGroup));
  2240. }
  2241. object SavePageControlState ()
  2242. {
  2243. if (requireStateControls == null) return null;
  2244. object[] state = new object [requireStateControls.Count];
  2245. bool allNull = true;
  2246. for (int n=0; n<state.Length; n++) {
  2247. state [n] = ((Control) requireStateControls [n]).SaveControlState ();
  2248. if (state [n] != null) allNull = false;
  2249. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  2250. if (trace != null)
  2251. trace.SaveControlState ((Control) requireStateControls [n], state [n]);
  2252. }
  2253. if (allNull) return null;
  2254. else return state;
  2255. }
  2256. void LoadPageControlState (object data)
  2257. {
  2258. _savedControlState = (object []) data;
  2259. if (requireStateControls == null) return;
  2260. int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
  2261. for (int n=0; n < max; n++) {
  2262. Control ctl = (Control) requireStateControls [n];
  2263. ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
  2264. }
  2265. }
  2266. void LoadPreviousPageReference ()
  2267. {
  2268. if (_requestValueCollection != null) {
  2269. string prevPage = _requestValueCollection [PreviousPageID];
  2270. if (prevPage != null) {
  2271. #if TARGET_J2EE
  2272. if (getFacesContext () != null) {
  2273. IHttpHandler handler = Context.ApplicationInstance.GetHandler (Context, prevPage);
  2274. Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
  2275. if (_context.Items.Contains (CrossPagePostBack)) {
  2276. previousPage = (Page) _context.Items [CrossPagePostBack];
  2277. _context.Items.Remove (CrossPagePostBack);
  2278. }
  2279. return;
  2280. }
  2281. #else
  2282. IHttpHandler handler = PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  2283. previousPage = (Page) handler;
  2284. previousPage.isCrossPagePostBack = true;
  2285. Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
  2286. #endif
  2287. }
  2288. }
  2289. }
  2290. Hashtable contentTemplates;
  2291. [EditorBrowsable (EditorBrowsableState.Never)]
  2292. protected internal void AddContentTemplate (string templateName, ITemplate template)
  2293. {
  2294. if (contentTemplates == null)
  2295. contentTemplates = new Hashtable ();
  2296. contentTemplates [templateName] = template;
  2297. }
  2298. PageTheme _pageTheme;
  2299. internal PageTheme PageTheme {
  2300. get { return _pageTheme; }
  2301. }
  2302. PageTheme _styleSheetPageTheme;
  2303. internal PageTheme StyleSheetPageTheme {
  2304. get { return _styleSheetPageTheme; }
  2305. }
  2306. Stack dataItemCtx;
  2307. internal void PushDataItemContext (object o) {
  2308. if (dataItemCtx == null)
  2309. dataItemCtx = new Stack ();
  2310. dataItemCtx.Push (o);
  2311. }
  2312. internal void PopDataItemContext () {
  2313. if (dataItemCtx == null)
  2314. throw new InvalidOperationException ();
  2315. dataItemCtx.Pop ();
  2316. }
  2317. public object GetDataItem() {
  2318. if (dataItemCtx == null || dataItemCtx.Count == 0)
  2319. throw new InvalidOperationException ("No data item");
  2320. return dataItemCtx.Peek ();
  2321. }
  2322. protected internal override void OnInit (EventArgs e)
  2323. {
  2324. base.OnInit (e);
  2325. ArrayList themes = new ArrayList();
  2326. if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
  2327. themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
  2328. if (PageTheme != null && PageTheme.GetStyleSheets () != null)
  2329. themes.AddRange (PageTheme.GetStyleSheets ());
  2330. if (themes.Count > 0 && Header == null)
  2331. throw new InvalidOperationException ("Using themed css files requires a header control on the page.");
  2332. foreach (string lss in themes) {
  2333. HtmlLink hl = new HtmlLink ();
  2334. hl.Href = lss;
  2335. hl.Attributes["type"] = "text/css";
  2336. hl.Attributes["rel"] = "stylesheet";
  2337. Header.Controls.Add (hl);
  2338. }
  2339. }
  2340. #endif
  2341. #if NET_2_0
  2342. [MonoTODO ("Not implemented. Only used by .net aspx parser")]
  2343. protected object GetWrappedFileDependencies (string [] list)
  2344. {
  2345. return list;
  2346. }
  2347. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  2348. protected virtual void InitializeCulture ()
  2349. {
  2350. }
  2351. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  2352. protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
  2353. {
  2354. }
  2355. #endif
  2356. }
  2357. }