1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
//------------------------------------------------------------------------------
// <copyright file="WmlFormAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.Web.Security;
using System.Security.Permissions;
#if COMPILING_FOR_SHIPPED_SOURCE
namespace System.Web.UI.MobileControls.ShippedAdapterSource
#else
namespace System.Web.UI.MobileControls.Adapters
#endif
{
/*
* WmlFormAdapter base class contains wml specific methods.
*
* Copyright (c) 2000 Microsoft Corporation
*/
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter"]/*' />
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class WmlFormAdapter : WmlControlAdapter
{
private IDictionary _postBackVariables = null;
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.Control"]/*' />
protected new Form Control
{
get
{
return (Form)base.Control;
}
}
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.Render"]/*' />
public override void Render(WmlMobileTextWriter writer)
{
String formsAuthCookieName = FormsAuthentication.FormsCookieName;
if(!Device.SupportsRedirectWithCookie)
{
if(!String.IsNullOrEmpty(formsAuthCookieName))
{
HttpContext.Current.Response.Cookies.Remove(formsAuthCookieName);
}
}
writer.BeginForm(Control);
if (Page.Adapter.PersistCookielessData &&
Device.CanRenderOneventAndPrevElementsTogether &&
!String.IsNullOrEmpty(formsAuthCookieName) &&
Control == Page.ActiveForm )
{
IDictionary dictionary = PageAdapter.CookielessDataDictionary;
if(dictionary != null)
{
String value = (String)dictionary[formsAuthCookieName];
if(!String.IsNullOrEmpty(value))
{
writer.AddFormVariable("__facn", value, false);
}
}
}
MobileControl secondaryUIControl = SecondaryUIControl as MobileControl;
writer.EnterLayout(Style);
if (secondaryUIControl != null && secondaryUIControl.Form == Control)
{
SetControlPageRecursive(secondaryUIControl, -1);
secondaryUIControl.RenderControl(writer);
}
else
{
if (Control.HasControls())
{
Panel header = Control.Header;
Panel footer = Control.Footer;
if (header != null)
{
writer.BeginCustomMarkup();
header.RenderControl(writer);
writer.EndCustomMarkup();
}
foreach(Control control in Control.Controls)
{
if (control != header && control != footer)
{
control.RenderControl(writer);
}
}
RenderPager(writer);
if (footer != null)
{
writer.BeginCustomMarkup();
footer.RenderControl(writer);
writer.EndCustomMarkup();
}
}
else
{
RenderPager(writer);
}
}
writer.ExitLayout(Style);
writer.EndForm();
}
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.RenderPager"]/*' />
protected virtual void RenderPager(WmlMobileTextWriter writer)
{
PagerStyle pagerStyle = Control.PagerStyle;
int pageCount = Control.PageCount;
if (pageCount <= 1)
{
return;
}
int page = Control.CurrentPage;
writer.EnterStyle(pagerStyle);
if (page < pageCount)
{
String nextPageText = pagerStyle.GetNextPageText(page);
RenderPostBackEvent(writer,
(page + 1).ToString(CultureInfo.InvariantCulture),
writer.IsValidSoftkeyLabel(nextPageText) ? nextPageText
: GetDefaultLabel(NextLabel),
true,
nextPageText,
true);
}
if (page > 1)
{
String prevPageText = pagerStyle.GetPreviousPageText(page);
RenderPostBackEvent(writer,
(page - 1).ToString(CultureInfo.InvariantCulture),
writer.IsValidSoftkeyLabel(prevPageText) ? prevPageText
: GetDefaultLabel(PreviousLabel),
true,
prevPageText,
true);
}
writer.ExitStyle(pagerStyle);
}
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.CalculatePostBackVariables"]/*' />
public virtual IDictionary CalculatePostBackVariables()
{
if (_postBackVariables == null)
{
_postBackVariables = new ListDictionary();
BuildControlPostBacksRecursive(Control);
}
return _postBackVariables;
}
private void BuildControlPostBacksRecursive(Control control)
{
if (control is IPostBackDataHandler
&& !(control is IPostBackEventHandler)
&& control.Visible && control != Control)
{
MobileControl mobileCtl = control as MobileControl;
if (mobileCtl != null && !mobileCtl.IsVisibleOnPage(Control.CurrentPage))
{
String s = GetControlPostBackValue(mobileCtl);
if (s != null)
{
_postBackVariables[control] = s;
}
}
else
{
_postBackVariables[control] = null;
}
}
if (control.HasControls())
{
foreach (Control child in control.Controls)
{
BuildControlPostBacksRecursive(child);
}
}
}
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.HandlePostBackEvent"]/*' />
public override bool HandlePostBackEvent(String eventArgument)
{
String eventSource = eventArgument;
int comma = eventSource.IndexOf(',');
if (comma == -1)
{
eventArgument = null;
}
else
{
eventArgument = eventSource.Substring(comma + 1);
eventSource = eventSource.Substring(0, comma);
}
if (eventSource.Length > 0)
{
Control sourceControl = Page.FindControl(eventSource);
if (sourceControl != null && sourceControl is IPostBackEventHandler)
{
((IPostBackEventHandler)sourceControl).RaisePostBackEvent(eventArgument);
}
}
return true;
}
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.RenderExtraCardElements"]/*' />
protected internal virtual void RenderExtraCardElements(WmlMobileTextWriter writer)
{
Form form = this.Control as Form;
if((form != null) && (form.Script != null))
{
foreach(Control childControl in form.Script.Controls)
{
LiteralControl lc = childControl as LiteralControl;
if(lc != null)
{
writer.Write(lc.Text);
}
else
{
DataBoundLiteralControl dlc = childControl as DataBoundLiteralControl;
if(dlc != null)
{
writer.Write(dlc.Text);
}
}
}
}
}
/// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.RenderCardTag"]/*' />
protected internal virtual void RenderCardTag(WmlMobileTextWriter writer, IDictionary attributes)
{
writer.WriteBeginTag("card");
if (attributes != null)
{
foreach (DictionaryEntry entry in attributes)
{
writer.WriteAttribute((String)entry.Key, (String)entry.Value, true);
}
}
writer.WriteLine(">");
}
/////////////////////////////////////////////////////////////////////////
// SECONDARY UI SUPPORT
/////////////////////////////////////////////////////////////////////////
private Control _secondaryUIControl;
private int _secondaryUIMode;
internal int GetSecondaryUIMode(Control control)
{
return (control != null && _secondaryUIControl == control) ? _secondaryUIMode : NotSecondaryUI;
}
internal void SetSecondaryUIMode(Control control, int mode)
{
if (mode != NotSecondaryUI)
{
if (_secondaryUIControl != null && _secondaryUIControl != control)
{
throw new Exception(
SR.GetString(SR.FormAdapterMultiControlsAttemptSecondaryUI));
}
_secondaryUIControl = control;
_secondaryUIMode = mode;
return;
}
if (control == _secondaryUIControl)
{
_secondaryUIControl = null;
}
}
internal Control SecondaryUIControl
{
get
{
return _secondaryUIControl;
}
}
//identical to method in htmlformadapter
private static void SetControlPageRecursive(Control control, int page)
{
MobileControl mc = control as MobileControl;
if(mc != null)
{
mc.FirstPage = page;
mc.LastPage = page;
}
if (control.HasControls())
{
foreach (Control child in control.Controls)
{
MobileControl mobileChild = child as MobileControl;
if (mobileChild != null)
{
mobileChild.FirstPage = page;
mobileChild.LastPage = page;
}
else
{
SetControlPageRecursive(child, page);
}
}
}
}
}
}
|