PageAdapter.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // System.Web.UI.Adapters.PageAdapter
  3. //
  4. // Author:
  5. // Dick Porter <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System.Web.UI;
  30. using System.Web.UI.WebControls;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. namespace System.Web.UI.Adapters
  34. {
  35. public abstract class PageAdapter : ControlAdapter
  36. {
  37. protected PageAdapter ()
  38. {
  39. }
  40. internal PageAdapter (Page p) : base (p)
  41. {
  42. }
  43. public virtual StringCollection CacheVaryByHeaders {
  44. get { return null; }
  45. }
  46. public virtual StringCollection CacheVaryByParams {
  47. get { return null; }
  48. }
  49. protected string ClientState
  50. {
  51. get {
  52. return Page.GetSavedViewState ();
  53. }
  54. }
  55. public virtual NameValueCollection DeterminePostBackMode ()
  56. {
  57. return Page.DeterminePostBackMode ();
  58. }
  59. public virtual ICollection GetRadioButtonsByGroup (string groupName)
  60. {
  61. if (radio_button_group == null)
  62. return new ArrayList();
  63. ArrayList radioButtons = (ArrayList) radio_button_group [groupName];
  64. if (radioButtons == null)
  65. return new ArrayList();
  66. return radioButtons;
  67. }
  68. public virtual PageStatePersister GetStatePersister ()
  69. {
  70. return new HiddenFieldPageStatePersister ((Page)Control);
  71. }
  72. public virtual void RegisterRadioButton (RadioButton radioButton)
  73. {
  74. if (radio_button_group == null)
  75. radio_button_group = new ListDictionary();
  76. ArrayList radioButtons = (ArrayList) radio_button_group [radioButton.GroupName];
  77. if (radioButtons == null)
  78. radio_button_group [radioButton.GroupName] = radioButtons = new ArrayList();
  79. if (!radioButtons.Contains(radioButton))
  80. radioButtons.Add(radioButton);
  81. }
  82. public virtual void RenderBeginHyperlink (HtmlTextWriter w,
  83. string targetUrl,
  84. bool encodeUrl,
  85. string softKeyLabel)
  86. {
  87. InternalRenderBeginHyperlink (w, targetUrl, encodeUrl, softKeyLabel, null);
  88. }
  89. public virtual void RenderBeginHyperlink (HtmlTextWriter w,
  90. string targetUrl,
  91. bool encodeUrl,
  92. string softKeyLabel,
  93. string accessKey)
  94. {
  95. if (accessKey != null && accessKey.Length > 1)
  96. throw new ArgumentOutOfRangeException("accessKey");
  97. InternalRenderBeginHyperlink (w, targetUrl, encodeUrl, softKeyLabel, accessKey);
  98. }
  99. void InternalRenderBeginHyperlink (HtmlTextWriter w,
  100. string targetUrl,
  101. bool encodeUrl,
  102. string softKeyLabel,
  103. string accessKey)
  104. {
  105. w.AddAttribute (HtmlTextWriterAttribute.Href, targetUrl, encodeUrl);
  106. if (accessKey != null)
  107. w.AddAttribute (HtmlTextWriterAttribute.Accesskey, accessKey);
  108. w.RenderBeginTag (HtmlTextWriterTag.A);
  109. }
  110. public virtual void RenderEndHyperlink (HtmlTextWriter w)
  111. {
  112. w.RenderEndTag();
  113. }
  114. public virtual void RenderPostBackEvent (HtmlTextWriter w,
  115. string target,
  116. string argument,
  117. string softKeyLabel,
  118. string text)
  119. {
  120. RenderPostBackEvent (w, target, argument, softKeyLabel, text, Page.Request.FilePath, null, true);
  121. }
  122. public virtual void RenderPostBackEvent (HtmlTextWriter w,
  123. string target,
  124. string argument,
  125. string softKeyLabel,
  126. string text,
  127. string postUrl,
  128. string accessKey)
  129. {
  130. RenderPostBackEvent (w, target, argument, softKeyLabel, text, postUrl, accessKey, true);
  131. }
  132. protected void RenderPostBackEvent (HtmlTextWriter w,
  133. string target,
  134. string argument,
  135. string softKeyLabel,
  136. string text,
  137. string postUrl,
  138. string accessKey,
  139. bool encode)
  140. {
  141. string url = String.Format ("{0}?__VIEWSTATE={1}&__EVENTTARGET={2}&__EVENTARGUMENT={3}&__PREVIOUSPAGE={4}",
  142. postUrl, HttpUtility.UrlEncode (Page.GetSavedViewState ()), target, argument, Page.Request.FilePath);
  143. RenderBeginHyperlink (w, url, encode, softKeyLabel, accessKey);
  144. w.Write(text);
  145. RenderEndHyperlink(w);
  146. }
  147. public virtual string TransformText (string text)
  148. {
  149. return text;
  150. }
  151. protected internal virtual string GetPostBackFormReference (string formID)
  152. {
  153. return String.Format("document.forms['{0}']", formID);
  154. }
  155. ListDictionary radio_button_group;
  156. }
  157. }
  158. #endif