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
|
//------------------------------------------------------------------------------
// <copyright file="HtmlCommandAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Drawing;
using System.Security.Permissions;
#if COMPILING_FOR_SHIPPED_SOURCE
namespace System.Web.UI.MobileControls.ShippedAdapterSource
#else
namespace System.Web.UI.MobileControls.Adapters
#endif
{
/*
* HtmlCommandAdapter class.
*
* Copyright (c) 2000 Microsoft Corporation
*/
/// <include file='doc\HtmlCommandAdapter.uex' path='docs/doc[@for="HtmlCommandAdapter"]/*' />
[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 HtmlCommandAdapter : HtmlControlAdapter
{
/// <include file='doc\HtmlCommandAdapter.uex' path='docs/doc[@for="HtmlCommandAdapter.Control"]/*' />
protected new Command Control
{
get
{
return (Command)base.Control;
}
}
/// <include file='doc\HtmlCommandAdapter.uex' path='docs/doc[@for="HtmlCommandAdapter.Render"]/*' />
public override void Render(HtmlMobileTextWriter writer)
{
bool renderLink = false;
bool renderImage = false;
// If image is defined and renderable, just do it. Otherwise,
// render as a link if specified.
if (!String.IsNullOrEmpty(Control.ImageUrl) &&
Device.SupportsImageSubmit)
{
renderImage = true;
}
else if (Control.Format == CommandFormat.Link &&
Device.JavaScript)
{
renderLink = true;
}
if (renderLink)
{
writer.EnterStyle(Style);
Form form = Control.Form;
if (form.Action.Length > 0)
{
writer.Write("<a href=\"javascript:document.");
writer.Write(form.ClientID);
writer.Write(".submit()\"");
AddAttributes(writer);
writer.Write(">");
writer.WriteText(Control.Text, true);
writer.WriteEndTag("a");
}
else
{
RenderBeginLink(writer, Constants.FormIDPrefix + form.UniqueID);
writer.WriteText(Control.Text, true);
RenderEndLink(writer);
}
writer.ExitStyle(Style, Control.BreakAfter);
}
else
{
writer.EnterLayout(Style);
writer.WriteBeginTag("input");
writer.WriteAttribute("name", Control.UniqueID);
if (renderImage)
{
writer.WriteAttribute("type", "image");
writer.WriteAttribute("src", Control.ResolveUrl(Control.ImageUrl), true);
writer.WriteAttribute("alt", Control.Text, true);
}
else
{
writer.WriteAttribute("type", "submit");
writer.Write(" value=\"");
writer.WriteText(Control.Text, true);
writer.Write("\"");
}
AddAttributes(writer);
writer.Write("/>");
writer.ExitLayout(Style, Control.BreakAfter);
}
}
/// <include file='doc\HtmlCommandAdapter.uex' path='docs/doc[@for="HtmlCommandAdapter.LoadPostData"]/*' />
public override bool LoadPostData(String key,
NameValueCollection data,
Object controlPrivateData,
out bool dataChanged)
{
dataChanged = false;
// HTML input tags of type image postback with the coordinates
// of the click rather than the name of the control.
String name = Control.UniqueID;
String postX = data[name + ".x"];
String postY = data[name + ".y"];
if (postX != null && postY != null
&& postX.Length > 0 && postY.Length > 0)
{
// set dataChannged to cause RaisePostDataChangedEvent()
dataChanged = true;
return true;
}
// For other command control, defer to default logic in control.
return false;
}
}
}
|