Walkthrough: Creating a custom UserControl task


Summary This walkthrough topic illustrates how to create a custom usercontrol task. The Usercontrol task provides design time experience for designing and configuring the custom task. It is also possible to integrate usecontrol task with manager application and configure from with the manager application.

Click here to get the sample associated with this walkthrough.

Creating a UserControlTask

  1. Open Visual Studio and choose to create a ASP.Net website. Add supporting controls on the page. The first control should be the ScriptManager control and then add ArcGIS controls. For this walkthrough following controls need be added to the page: MapResourceManager ,Map ,TaskManager, ASP Menu and TaskResults control. At runtime, the TaskResults control displays the results of your custom UserControlTask.
  2. While in design mode of the web form, select the Toolbox panel, and expand the ArcGIS Web Controls tab. Drag and drop a UserControlTask control into the TaskManager control. See the following screen shot showing the page in Visual Studio:


  3. To create a custom ASP.NET Web User control, right-click the Web site and select Add New Item. The Add New Item dialog box appears.
  4. On the Add New Item dialog box, select the Web User Control template, then click Add. See the following screen shot: 
 
  1. To expose a User control to the ADF task framework, open the code-behind page for the User control and subclass the UserControlTaskPanel class. Right-click the UserControlTaskPanel text in the code and select Implement Abstract Class. An override for the ExecuteTask method is added to the class definition. See the following screen shot:
 
  1. In traditional server control development, controls are added and placed programmatically. In the User control, drag and drop, then place server controls on the page (or add in markup) using the design view in Visual Studio. Add an ASP.NET panel and insert a TextBox and Button item. The unique ID for each is, MyPanel, InputTextBox, and ExecuteButton, respectively. The Panel defines the display surface of the User control at runtime. See the following screen shot that shows the design view for the User control:

 
  1. When the Button item is clicked in the User control, the task executes. Since the UserControlTask only supports partial postbacks, you can handle events using the standard postback architecture. Double-click the Button item to create the click event handler in the code-behind page. To start execution on a task, call the Start method on the base class (UserControlTaskPanel) and provide an object that contains a parameter to process. In this case, pass the text in the TextBox. See the following code example:
[C#]
protected void ExecuteButton_Click(object sender, EventArgs e)
{
    this.Start(InputTextBox.Text);
}
  1. ADF controls are AJAX enabled; therefore, if an ADF control exists in a User control task, it registers with the ScriptManager. Many ASP.NET server controls are not AJAX enabled. As a result, the ASP.NET server controls must be registered with the ScriptManager to generate a partial postback. In this case, register the Button item with the ScriptManager as an AJAX control. Since the ScriptManager is on the page that contains the User control, use the static GetCurrent method and provide the Page container for the User control to get a reference to the ScriptManager. See the following code example:
[C#]
protected void Page_Load(object sender, EventArgs e)
{
    System.Web.UI.ScriptManager scriptManager =
        System.Web.UI.ScriptManager.GetCurrent(this.Page);
    scriptManager.RegisterAsyncPostBackControl(ExecuteButton);
}
  1. The parameters provided with the Start method (Step 7) are passed to the ExecuteTask method. The ExecuteTask method contains the business logic for processing task inputs and generating output. Various task result types can be returned from the ExecuteTask method. In this case, a simple task result containing server time is generated, returned to the client browser, and displayed in a TaskResults control. The implementation code for the User control task is now complete. See the following code example: 
[C#]
public override object ExecuteTask(object parameters)
{
    string textBoxValue = parameters as string;

    // Demo purposes only
    System.Threading.Thread.Sleep(500);

    System.DateTime now = System.DateTime.Now;

    string heading = string.Format("The time on the server is {0}:{1:d2}:{2:d2}",
        now.Hour, now.Minute, now.Second);

    string detail = string.Format("The value in the text box is: {0}", textBoxValue);

    ESRI.ArcGIS.ADF.Web.UI.WebControls.SimpleTaskResult simpleTaskResult = new
        ESRI.ArcGIS.ADF.Web.UI.WebControls.SimpleTaskResult(heading, detail);

    return simpleTaskResult;
}
  1. The custom usercontroltask is ready to use. It needs to be hooked to the UsercontrolTask control you added in step2. Got to default page, while in design mode, set the UserControlTask control properties. Click the UserControlTask control and display the verbs associated with the control. See the following screen shot:


    1. To show the results of a task, buddy the task control with the TaskResults control. Select the Choose Task Results container verb to modify the TaskResultsContainers property. On the BuddyControl Collection Editor dialog box, add a new item and select the ID of the TaskResults control you want to show in the task results. See the following screen shot:


    2. On the Properties page for the UserControlTask, set the path to the User control task. Make the path relative to the Web application. See the following screen shot: 

  1. Run the application. The Menu control lists the User control task. The User control task displays by default. Type a value in the text box on the Simple User Control Task dialog box, for example, Hello World. The text typed in the text box and the time on the server is returned in the TaskResults control. See the following screen shot:




See Also:

UserControl task Manager integration
Creating a custom server task
Task runtime workflow