PageAdapter.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // System.Web.UI.Adapters.PageAdapter
  3. //
  4. // Author:
  5. // Dick Porter <[email protected]>
  6. //
  7. // Copyright (C) 2005-2010 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. using System.Web.UI;
  29. using System.Web.UI.WebControls;
  30. using System.Collections;
  31. using System.Collections.Specialized;
  32. namespace System.Web.UI.Adapters
  33. {
  34. public abstract class PageAdapter : ControlAdapter
  35. {
  36. protected PageAdapter ()
  37. {
  38. }
  39. internal PageAdapter (Page p) : base (p)
  40. {
  41. }
  42. public virtual StringCollection CacheVaryByHeaders {
  43. get { return null; }
  44. }
  45. public virtual StringCollection CacheVaryByParams {
  46. get { return null; }
  47. }
  48. protected string ClientState
  49. {
  50. get {
  51. return Page.GetSavedViewState ();
  52. }
  53. }
  54. public virtual NameValueCollection DeterminePostBackMode ()
  55. {
  56. return Page.DeterminePostBackMode ();
  57. }
  58. public virtual ICollection GetRadioButtonsByGroup (string groupName)
  59. {
  60. if (radio_button_group == null)
  61. return new ArrayList();
  62. ArrayList radioButtons = (ArrayList) radio_button_group [groupName];
  63. if (radioButtons == null)
  64. return new ArrayList();
  65. return radioButtons;
  66. }
  67. public virtual PageStatePersister GetStatePersister ()
  68. {
  69. return new HiddenFieldPageStatePersister ((Page)Control);
  70. }
  71. public virtual void RegisterRadioButton (RadioButton radioButton)
  72. {
  73. if (radio_button_group == null)
  74. radio_button_group = new ListDictionary();
  75. ArrayList radioButtons = (ArrayList) radio_button_group [radioButton.GroupName];
  76. if (radioButtons == null)
  77. radio_button_group [radioButton.GroupName] = radioButtons = new ArrayList();
  78. if (!radioButtons.Contains(radioButton))
  79. radioButtons.Add(radioButton);
  80. }
  81. public virtual void RenderBeginHyperlink (HtmlTextWriter w,
  82. string targetUrl,
  83. bool encodeUrl,
  84. string softKeyLabel)
  85. {
  86. InternalRenderBeginHyperlink (w, targetUrl, encodeUrl, softKeyLabel, null);
  87. }
  88. public virtual void RenderBeginHyperlink (HtmlTextWriter w,
  89. string targetUrl,
  90. bool encodeUrl,
  91. string softKeyLabel,
  92. string accessKey)
  93. {
  94. if (accessKey != null && accessKey.Length > 1)
  95. throw new ArgumentOutOfRangeException("accessKey");
  96. InternalRenderBeginHyperlink (w, targetUrl, encodeUrl, softKeyLabel, accessKey);
  97. }
  98. void InternalRenderBeginHyperlink (HtmlTextWriter w,
  99. string targetUrl,
  100. bool encodeUrl,
  101. string softKeyLabel,
  102. string accessKey)
  103. {
  104. w.AddAttribute (HtmlTextWriterAttribute.Href, targetUrl, encodeUrl);
  105. if (accessKey != null)
  106. w.AddAttribute (HtmlTextWriterAttribute.Accesskey, accessKey);
  107. w.RenderBeginTag (HtmlTextWriterTag.A);
  108. }
  109. public virtual void RenderEndHyperlink (HtmlTextWriter w)
  110. {
  111. w.RenderEndTag();
  112. }
  113. public virtual void RenderPostBackEvent (HtmlTextWriter w,
  114. string target,
  115. string argument,
  116. string softKeyLabel,
  117. string text)
  118. {
  119. RenderPostBackEvent (w, target, argument, softKeyLabel, text, Page.Request.FilePath, null, true);
  120. }
  121. public virtual void RenderPostBackEvent (HtmlTextWriter w,
  122. string target,
  123. string argument,
  124. string softKeyLabel,
  125. string text,
  126. string postUrl,
  127. string accessKey)
  128. {
  129. RenderPostBackEvent (w, target, argument, softKeyLabel, text, postUrl, accessKey, true);
  130. }
  131. protected void RenderPostBackEvent (HtmlTextWriter w,
  132. string target,
  133. string argument,
  134. string softKeyLabel,
  135. string text,
  136. string postUrl,
  137. string accessKey,
  138. bool encode)
  139. {
  140. string url = String.Format ("{0}?__VIEWSTATE={1}&__EVENTTARGET={2}&__EVENTARGUMENT={3}&__PREVIOUSPAGE={4}",
  141. postUrl, HttpUtility.UrlEncode (Page.GetSavedViewState ()), target, argument, Page.Request.FilePath);
  142. RenderBeginHyperlink (w, url, encode, softKeyLabel, accessKey);
  143. w.Write(text);
  144. RenderEndHyperlink(w);
  145. }
  146. public virtual string TransformText (string text)
  147. {
  148. return text;
  149. }
  150. protected internal virtual string GetPostBackFormReference (string formID)
  151. {
  152. return String.Format("document.forms['{0}']", formID);
  153. }
  154. ListDictionary radio_button_group;
  155. }
  156. }