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
|
//------------------------------------------------------------------------------
// <copyright file="Command.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing.Design;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
namespace System.Web.UI.MobileControls
{
/*
* Mobile Command class.
*
* Copyright (c) 2000 Microsoft Corporation
*/
/// <include file='doc\Command.uex' path='docs/doc[@for="Command"]/*' />
[
DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + AssemblyRef.SystemDesign),
DefaultEvent("Click"),
DefaultProperty("Text"),
Designer(typeof(System.Web.UI.Design.MobileControls.CommandDesigner)),
DesignerAdapter(typeof(System.Web.UI.Design.MobileControls.Adapters.DesignerCommandAdapter)),
ToolboxData("<{0}:Command runat=\"server\">Command</{0}:Command>"),
ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, " + AssemblyRef.SystemDesign)
]
[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 Command : TextControl, IPostBackEventHandler, IPostBackDataHandler
{
private static readonly Object EventClick = new Object ();
private static readonly Object EventItemCommand = new Object ();
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.OnPreRender"]/*' />
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// If this control will be rendered as an image
Debug.Assert(ImageUrl != null);
if (MobilePage != null
&& ImageUrl.Length != 0
&& MobilePage.Device.SupportsImageSubmit)
{
// HTML input controls of type image postback as name.x and
// name.y which is not associated with this control by default
// in Page.ProcessPostData().
MobilePage.RegisterRequiresPostBack(this);
}
}
/// <internalonly/>
protected bool LoadPostData(String key, NameValueCollection data)
{
bool dataChanged;
bool handledByAdapter =
Adapter.LoadPostData(key, data, null, out dataChanged);
// If the adapter handled the post back and set dataChanged this
// was an image button (responds with ID.x and ID.y).
if (handledByAdapter)
{
if(dataChanged)
{
Page.RegisterRequiresRaiseEvent(this);
}
}
// Otherwise if the adapter did not handle the past back, use
// the same method as Page.ProcessPostData().
else if(data[key] != null)
{
Page.RegisterRequiresRaiseEvent(this);
}
return false; // no need to raise PostDataChangedEvent.
}
/// <internalonly/>
protected void RaisePostDataChangedEvent() {
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.SoftkeyLabel"]/*' />
[
Bindable(true),
DefaultValue(""),
MobileCategory(SR.Category_Behavior),
MobileSysDescription(SR.Command_SoftkeyLabel)
]
public String SoftkeyLabel
{
get
{
String s = (String) ViewState["Softkeylabel"];
return((s != null) ? s : String.Empty);
}
set
{
ViewState["Softkeylabel"] = value;
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.CommandName"]/*' />
[
Bindable(true),
DefaultValue(""),
MobileCategory(SR.Category_Behavior),
MobileSysDescription(SR.Command_CommandName)
]
public String CommandName
{
get
{
String s = (String) ViewState["CommandName"];
return((s != null) ? s : String.Empty);
}
set
{
ViewState["CommandName"] = value;
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.CommandArgument"]/*' />
[
Bindable(true),
DefaultValue(""),
MobileCategory(SR.Category_Behavior),
MobileSysDescription(SR.Command_CommandArgument)
]
public String CommandArgument
{
get
{
String s = (String) ViewState["CommandArgument"];
return((s != null) ? s : String.Empty);
}
set
{
ViewState["CommandArgument"] = value;
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.ImageUrl"]/*' />
[
Bindable(true),
DefaultValue(""),
Editor(typeof(System.Web.UI.Design.MobileControls.ImageUrlEditor),
typeof(UITypeEditor)),
MobileCategory(SR.Category_Appearance),
MobileSysDescription(SR.Image_ImageUrl)
]
public String ImageUrl
{
get
{
String s = (String) ViewState["ImageUrl"];
return((s != null) ? s : String.Empty);
}
set
{
ViewState["ImageUrl"] = value;
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.CausesValidation"]/*' />
[
Bindable(false),
DefaultValue(true),
MobileCategory(SR.Category_Behavior),
MobileSysDescription(SR.Command_CausesValidation)
]
public bool CausesValidation
{
get
{
object b = ViewState["CausesValidation"];
return((b == null) ? true : (bool)b);
}
set
{
ViewState["CausesValidation"] = value;
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.Format"]/*' />
[
Bindable(true),
DefaultValue(CommandFormat.Button),
MobileCategory(SR.Category_Appearance),
MobileSysDescription(SR.Command_Format)
]
public CommandFormat Format
{
get
{
Object o = ViewState["Format"];
return((o == null) ? CommandFormat.Button : (CommandFormat)o);
}
set
{
ViewState["Format"] = value;
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.OnClick"]/*' />
protected virtual void OnClick(EventArgs e)
{
EventHandler onClickHandler = (EventHandler)Events[EventClick];
if (onClickHandler != null)
{
onClickHandler(this,e);
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.OnItemCommand"]/*' />
protected virtual void OnItemCommand(CommandEventArgs e)
{
CommandEventHandler onItemCommandHandler = (CommandEventHandler)Events[EventItemCommand];
if (onItemCommandHandler != null)
{
onItemCommandHandler(this,e);
}
RaiseBubbleEvent (this, e);
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.Click"]/*' />
[
MobileCategory(SR.Category_Action),
MobileSysDescription(SR.Command_OnClick)
]
public event EventHandler Click
{
add
{
Events.AddHandler(EventClick, value);
}
remove
{
Events.RemoveHandler(EventClick, value);
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.ItemCommand"]/*' />
[
MobileCategory(SR.Category_Action),
MobileSysDescription(SR.Command_OnItemCommand)
]
public event CommandEventHandler ItemCommand
{
add
{
Events.AddHandler(EventItemCommand, value);
}
remove
{
Events.RemoveHandler(EventItemCommand, value);
}
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.IPostBackEventHandler.RaisePostBackEvent"]/*' />
/// <internalonly/>
protected void RaisePostBackEvent(String argument)
{
if (CausesValidation)
{
MobilePage.Validate();
}
// It is legitimate to reset the form back to the first page
// after a form submit.
Form.CurrentPage = 1;
OnClick (EventArgs.Empty);
OnItemCommand (new CommandEventArgs(CommandName, CommandArgument));
}
/// <include file='doc\Command.uex' path='docs/doc[@for="Command.IsFormSubmitControl"]/*' />
protected override bool IsFormSubmitControl()
{
return true;
}
#region IPostBackEventHandler implementation
void IPostBackEventHandler.RaisePostBackEvent(String eventArgument) {
RaisePostBackEvent(eventArgument);
}
#endregion
#region IPostBackDataHandler implementation
bool IPostBackDataHandler.LoadPostData(String key, NameValueCollection data) {
return LoadPostData(key, data);
}
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
#endregion
}
}
|