Common SimpleTaskCommon_SimpleTask_CSharpSimpleTask_CSharp\SimpleTask_CSharp.cs
// Copyright 2007 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using System.ComponentModel;
namespace SimpleTask_CSharp
{
[ToolboxData("<{0}:SimpleTask_CSharp runat=\"server\" Width=\"100px\" BorderWidth=\"1px\"> </{0}:SimpleTask_CSharp>")]
[ToolboxBitmap(typeof(SimpleTask_CSharp))]
[WebConfigurator(typeof(SimpleTaskWebConfigurator_CSharp))]
[Designer(typeof(SimpleTaskDesigner_CSharp))]
public class SimpleTask_CSharp: FloatingPanelTask
{
private TextBox textBox = null;
private TextBox phantomTextBox = null;
private HtmlInputButton button = null;
[Browsable(true)]
[Category("Appearance")]
[DefaultValue("Execute")]
[PersistenceMode(PersistenceMode.Attribute)]
public string ButtonText
{
get
{
object o = StateManager.GetProperty("buttonText");
return (o == null) ? "Execute" : o as string;
}
set
{
StateManager.SetProperty("buttonText", value);
}
}
protected override void CreateChildControls()
{
Controls.Clear();
base.CreateChildControls();
textBox = new TextBox();
textBox.ID = "textBox";
// The phantom text box is an invisible text box that causes the browser to
// not do a postback when the enter button is hit.
phantomTextBox = new TextBox();
phantomTextBox.ID = "phantomTextBox";
phantomTextBox.Style[HtmlTextWriterStyle.Display] = "none";
button = new HtmlInputButton();
button.ID = "button";
button.Value = ButtonText;
Controls.Add(textBox);
Controls.Add(phantomTextBox);
Controls.Add(button);
string getArgumentJS = string.Format("'textBoxValue=' + document.getElementById('{0}').value", textBox.ClientID);
string onClick = string.Format("executeTask({0},\"{1}\");", getArgumentJS, CallbackFunctionString);
string onKeyDown = string.Format("if(event.keyCode==13){{{0}return false;}}", onClick);
button.Attributes.Add("onclick", onClick);
textBox.Attributes.Add("onkeydown", onKeyDown);
}
public override string GetCallbackResult()
{
NameValueCollection keyValColl = CallbackUtility.ParseStringIntoNameValueCollection(_callbackArg);
Input = keyValColl["textBoxValue"];
return base.GetCallbackResult();
}
public override void ExecuteTask()
{
Results = null;
if (Input == null) return;
string textBoxValue = Input as string;
string heading = string.Format("The time on the server is {0}", DateTime.Now.ToShortTimeString());
string detail = string.Format("The value in the text box is: {0}", textBoxValue);
SimpleTaskResult str = new SimpleTaskResult(heading, detail);
Results = str;
}
public override void Refresh()
{
// we override the Refresh method so that we can assign Input to the
// TextBox's text before re-rendering.
string tmp = Input as string;
if (!string.IsNullOrEmpty(tmp)) textBox.Text = tmp;
base.Refresh();
}
public override List<GISResourceItemDependency> GetGISResourceItemDependencies()
{
List<GISResourceItemDependency> list = new List<GISResourceItemDependency>();
return list;
}
}
}