Page.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
  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.ServletRequest == null)
  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. }
  2250. if (allNull) return null;
  2251. else return state;
  2252. }
  2253. void LoadPageControlState (object data)
  2254. {
  2255. _savedControlState = (object []) data;
  2256. if (requireStateControls == null) return;
  2257. int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
  2258. for (int n=0; n < max; n++) {
  2259. Control ctl = (Control) requireStateControls [n];
  2260. ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
  2261. }
  2262. }
  2263. void LoadPreviousPageReference ()
  2264. {
  2265. if (_requestValueCollection != null) {
  2266. string prevPage = _requestValueCollection [PreviousPageID];
  2267. if (prevPage != null) {
  2268. #if TARGET_J2EE
  2269. if (getFacesContext () != null) {
  2270. IHttpHandler handler = Context.ApplicationInstance.GetHandler (Context, prevPage);
  2271. Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
  2272. if (_context.Items.Contains (CrossPagePostBack)) {
  2273. previousPage = (Page) _context.Items [CrossPagePostBack];
  2274. _context.Items.Remove (CrossPagePostBack);
  2275. }
  2276. return;
  2277. }
  2278. #else
  2279. IHttpHandler handler = PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  2280. previousPage = (Page) handler;
  2281. previousPage.isCrossPagePostBack = true;
  2282. Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
  2283. #endif
  2284. }
  2285. }
  2286. }
  2287. Hashtable contentTemplates;
  2288. [EditorBrowsable (EditorBrowsableState.Never)]
  2289. protected internal void AddContentTemplate (string templateName, ITemplate template)
  2290. {
  2291. if (contentTemplates == null)
  2292. contentTemplates = new Hashtable ();
  2293. contentTemplates [templateName] = template;
  2294. }
  2295. PageTheme _pageTheme;
  2296. internal PageTheme PageTheme {
  2297. get { return _pageTheme; }
  2298. }
  2299. PageTheme _styleSheetPageTheme;
  2300. internal PageTheme StyleSheetPageTheme {
  2301. get { return _styleSheetPageTheme; }
  2302. }
  2303. Stack dataItemCtx;
  2304. internal void PushDataItemContext (object o) {
  2305. if (dataItemCtx == null)
  2306. dataItemCtx = new Stack ();
  2307. dataItemCtx.Push (o);
  2308. }
  2309. internal void PopDataItemContext () {
  2310. if (dataItemCtx == null)
  2311. throw new InvalidOperationException ();
  2312. dataItemCtx.Pop ();
  2313. }
  2314. public object GetDataItem() {
  2315. if (dataItemCtx == null || dataItemCtx.Count == 0)
  2316. throw new InvalidOperationException ("No data item");
  2317. return dataItemCtx.Peek ();
  2318. }
  2319. protected internal override void OnInit (EventArgs e)
  2320. {
  2321. base.OnInit (e);
  2322. ArrayList themes = new ArrayList();
  2323. if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
  2324. themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
  2325. if (PageTheme != null && PageTheme.GetStyleSheets () != null)
  2326. themes.AddRange (PageTheme.GetStyleSheets ());
  2327. if (themes.Count > 0 && Header == null)
  2328. throw new InvalidOperationException ("Using themed css files requires a header control on the page.");
  2329. foreach (string lss in themes) {
  2330. HtmlLink hl = new HtmlLink ();
  2331. hl.Href = lss;
  2332. hl.Attributes["type"] = "text/css";
  2333. hl.Attributes["rel"] = "stylesheet";
  2334. Header.Controls.Add (hl);
  2335. }
  2336. }
  2337. #endif
  2338. #if NET_2_0
  2339. [MonoTODO ("Not implemented. Only used by .net aspx parser")]
  2340. protected object GetWrappedFileDependencies (string [] list)
  2341. {
  2342. return list;
  2343. }
  2344. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  2345. protected virtual void InitializeCulture ()
  2346. {
  2347. }
  2348. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  2349. protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
  2350. {
  2351. }
  2352. #endif
  2353. }
  2354. }