Page.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. //
  2. // System.Web.UI.Page
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc. (http://www.ximian.com)
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Specialized;
  13. using System.IO;
  14. using System.Reflection;
  15. using System.Security.Principal;
  16. using System.Web;
  17. using System.Web.Caching;
  18. using System.Web.SessionState;
  19. namespace System.Web.UI
  20. {
  21. public class Page : TemplateControl, IHttpHandler
  22. {
  23. private string _culture;
  24. private bool _viewState = true;
  25. private bool _viewStateMac = false;
  26. private string _errorPage;
  27. private ArrayList _fileDependencies;
  28. private string _ID;
  29. private bool _isPostBack;
  30. private bool _isValid;
  31. private HttpServerUtility _server;
  32. private bool _smartNavigation = false;
  33. private TraceContext _trace;
  34. private bool _traceEnabled;
  35. private TraceMode _traceModeValue;
  36. private int _transactionMode;
  37. private string _UICulture;
  38. private HttpContext _context;
  39. private ValidatorCollection _validators;
  40. private bool _visible;
  41. private string _responseEncoding;
  42. private HttpSessionState _session;
  43. #region Fields
  44. protected const string postEventArgumentID = ""; //FIXME
  45. protected const string postEventSourceID = "";
  46. #endregion
  47. #region Constructor
  48. public Page ()
  49. {
  50. }
  51. #endregion
  52. #region Properties
  53. [MonoTODO]
  54. public HttpApplicationState Application
  55. {
  56. get { throw new NotImplementedException (); }
  57. }
  58. bool AspCompatMode
  59. {
  60. set { throw new NotImplementedException (); }
  61. }
  62. [MonoTODO]
  63. bool Buffer
  64. {
  65. set { throw new NotImplementedException (); }
  66. }
  67. [MonoTODO]
  68. public Cache Cache
  69. {
  70. get { throw new NotImplementedException (); }
  71. }
  72. [MonoTODO]
  73. public string ClientTarget
  74. {
  75. get { throw new NotImplementedException (); }
  76. set { throw new NotImplementedException (); }
  77. }
  78. [MonoTODO]
  79. int CodePage
  80. {
  81. set { throw new NotImplementedException (); }
  82. }
  83. [MonoTODO]
  84. string ContentType
  85. {
  86. set { throw new NotImplementedException (); }
  87. }
  88. protected override HttpContext Context
  89. {
  90. get { return _context; }
  91. }
  92. string Culture
  93. {
  94. set { _culture = value; }
  95. }
  96. public override bool EnableViewState
  97. {
  98. get { return _viewState; }
  99. set { _viewState = value; }
  100. }
  101. protected bool EnableViewStateMac
  102. {
  103. get { return _viewStateMac; }
  104. set { _viewStateMac = value; }
  105. }
  106. public string ErrorPage
  107. {
  108. get { return _errorPage; }
  109. set { _errorPage = value; }
  110. }
  111. public ArrayList FileDependencies
  112. {
  113. set { _fileDependencies = value; }
  114. }
  115. public override string ID
  116. {
  117. get { return _ID; }
  118. set { _ID = value; }
  119. }
  120. public bool IsPostBack
  121. {
  122. get { return _isPostBack; }
  123. }
  124. [MonoTODO]
  125. public bool IsReusable
  126. {
  127. get { throw new NotImplementedException (); }
  128. }
  129. public bool IsValid
  130. {
  131. get { return _isValid; }
  132. }
  133. [MonoTODO]
  134. int LCID {
  135. set { throw new NotImplementedException (); }
  136. }
  137. public HttpRequest Request
  138. {
  139. get { return _context.Request; }
  140. }
  141. public HttpResponse Response
  142. {
  143. get { return _context.Response; }
  144. }
  145. string ResponseEncoding
  146. {
  147. set { _responseEncoding = value; }
  148. }
  149. public HttpServerUtility Server
  150. {
  151. get { return _server; }
  152. }
  153. public virtual HttpSessionState Session
  154. {
  155. get { return _session; }
  156. }
  157. public bool SmartNavigation
  158. {
  159. get { return _smartNavigation; }
  160. set { _smartNavigation = value; }
  161. }
  162. public TraceContext Trace
  163. {
  164. get { return _trace; }
  165. }
  166. bool TraceEnabled
  167. {
  168. set { _traceEnabled = value; }
  169. }
  170. TraceMode TraceModeValue
  171. {
  172. set { _traceModeValue = value; }
  173. }
  174. int TransactionMode
  175. {
  176. set { _transactionMode = value; }
  177. }
  178. string UICulture
  179. {
  180. set { _UICulture = value; }
  181. }
  182. public IPrincipal User
  183. {
  184. get { return _context.User; }
  185. }
  186. public ValidatorCollection Validators
  187. {
  188. get { return _validators; }
  189. }
  190. public override bool Visible
  191. {
  192. get { return _visible; }
  193. set { _visible = value; }
  194. }
  195. #endregion
  196. #region Methods
  197. [MonoTODO]
  198. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  199. AsyncCallback cb,
  200. object extraData)
  201. {
  202. throw new NotImplementedException ();
  203. }
  204. [MonoTODO]
  205. protected void AspcompatEndProcessRequest (IAsyncResult result)
  206. {
  207. throw new NotImplementedException ();
  208. }
  209. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  210. {
  211. return new HtmlTextWriter (tw);
  212. }
  213. [MonoTODO]
  214. public void DesignerInitialize ()
  215. {
  216. throw new NotImplementedException ();
  217. }
  218. [MonoTODO]
  219. protected virtual NameValueCollection DeterminePostBackMode ()
  220. {
  221. /* Why does this not compile? HttpSessionState has IsNewSession...
  222. if (_session.IsNewSession)
  223. return null;
  224. */
  225. if (IsPostBack)
  226. return _context.Request.Form; //FIXME: is this enough?
  227. throw new NotImplementedException ("GET method got to parse Request.QueryString");
  228. }
  229. [MonoTODO]
  230. public string GetPostBackClientEvent (Control control, string argument)
  231. {
  232. throw new NotImplementedException ();
  233. }
  234. [MonoTODO]
  235. public string GetPostBackClientHyperlink (Control control, string argument)
  236. {
  237. throw new NotImplementedException ();
  238. }
  239. [MonoTODO]
  240. public string GetPostBackEventReference (Control control)
  241. {
  242. throw new NotImplementedException ();
  243. }
  244. [MonoTODO]
  245. public string GetPostBackEventReference (Control control, string argument)
  246. {
  247. throw new NotImplementedException ();
  248. }
  249. public virtual int GetTypeHashCode ()
  250. {
  251. return this.GetHashCode ();
  252. }
  253. [MonoTODO]
  254. protected virtual void InitOutputCache (int duration,
  255. string varyByHeader,
  256. string varyByCustom,
  257. OutputCacheLocation location,
  258. string varyByParam)
  259. {
  260. throw new NotImplementedException ();
  261. }
  262. [MonoTODO]
  263. public bool IsClientScriptBlockRegistered (string key)
  264. {
  265. throw new NotImplementedException ();
  266. }
  267. [MonoTODO]
  268. public bool IsStartupScriptRegistered (string key)
  269. {
  270. throw new NotImplementedException ();
  271. }
  272. [MonoTODO]
  273. protected virtual object LoadPageStateFromPersistenceMedium ()
  274. {
  275. throw new NotImplementedException ();
  276. }
  277. [MonoTODO]
  278. public string MapPath (string virtualPath)
  279. {
  280. throw new NotImplementedException ();
  281. }
  282. private void InvokeEventMethod (string m_name, object sender, EventArgs e)
  283. {
  284. MethodInfo evt_method = GetType ().GetMethod(m_name,
  285. BindingFlags.IgnoreCase | BindingFlags.Public |
  286. BindingFlags.NonPublic | BindingFlags.DeclaredOnly |
  287. BindingFlags.Instance);
  288. if (evt_method != null){
  289. object [] parms = new object [2];
  290. parms [0] = sender;
  291. parms [1] = e;
  292. evt_method.Invoke (this, parms);
  293. }
  294. }
  295. private void Page_Init (object sender, EventArgs e)
  296. {
  297. InvokeEventMethod ("Page_Init", sender, e);
  298. }
  299. private void Page_Load (object sender, EventArgs e)
  300. {
  301. InvokeEventMethod ("Page_Load", sender, e);
  302. }
  303. public void ProcessRequest (HttpContext context)
  304. {
  305. FrameworkInitialize ();
  306. // This 2 should depend on AutoEventWireUp in Page directive. Defaults to true.
  307. Init += new EventHandler (Page_Init);
  308. Load += new EventHandler (Page_Load);
  309. //-- Control execution lifecycle in the docs
  310. OnInit (EventArgs.Empty);
  311. //LoadViewState ();
  312. //if (this is IPostBackDataHandler)
  313. // LoadPostData ();
  314. OnLoad (EventArgs.Empty);
  315. //if (this is IPostBackDataHandler)
  316. // RaisePostBackEvent ();
  317. OnPreRender (EventArgs.Empty);
  318. //--
  319. _context = context;
  320. HtmlTextWriter output = new HtmlTextWriter (context.Response.Output);
  321. foreach (Control ctrl in Controls){
  322. // Assing Control.Page here. Controls should do the same before
  323. // rendering their children
  324. ctrl.Page = this;
  325. ctrl.RenderControl (output);
  326. }
  327. }
  328. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  329. {
  330. sourceControl.RaisePostBackEvent (eventArgument);
  331. }
  332. [MonoTODO]
  333. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  334. {
  335. throw new NotImplementedException ();
  336. }
  337. [MonoTODO]
  338. public virtual void RegisterClientScriptBlock (string key, string script)
  339. {
  340. throw new NotImplementedException ();
  341. }
  342. [MonoTODO]
  343. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  344. {
  345. throw new NotImplementedException ();
  346. }
  347. [MonoTODO]
  348. public void RegisterClientScriptFile (string a, string b, string c)
  349. {
  350. throw new NotImplementedException ();
  351. }
  352. [MonoTODO]
  353. public void RegisterOnSubmitStatement (string key, string script)
  354. {
  355. throw new NotImplementedException ();
  356. }
  357. [MonoTODO]
  358. public void RegisterRequiresPostBack (Control control)
  359. {
  360. throw new NotImplementedException ();
  361. }
  362. [MonoTODO]
  363. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  364. {
  365. throw new NotImplementedException ();
  366. }
  367. [MonoTODO]
  368. public void RegisterViewStateHandler ()
  369. {
  370. throw new NotImplementedException ();
  371. }
  372. [MonoTODO]
  373. protected virtual void SavePageStatetoPersistenceMedium (object viewState)
  374. {
  375. throw new NotImplementedException ();
  376. }
  377. public virtual void Validate ()
  378. {
  379. bool all_valid = true;
  380. foreach (IValidator v in _validators){
  381. v.Validate ();
  382. if (v.IsValid == false)
  383. all_valid = false;
  384. }
  385. if (all_valid)
  386. _isValid = true;
  387. }
  388. [MonoTODO]
  389. public virtual void VerifyRenderingInServerForm (Control control)
  390. {
  391. return;
  392. }
  393. #endregion
  394. }
  395. }