Common Simple UserControlTask
SimpleUserControlTask_VBNET\UserControlTasks\SimpleTask\SimpleTask.ascx.vb
' Copyright 2011 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.
' 

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports ESRI.ArcGIS.ADF.Web.UI.WebControls

'Derive from UserControlTaskPanel
Partial Public Class SimpleTask
  Inherits UserControlTaskPanel
  Protected Overrides Sub OnLoad(ByVal e As EventArgs)
  'protected void Page_Load(object sender, System.EventArgs eventArgs)
'    #Region "Populate UI from task's configuration settings"
    MyBase.OnLoad(e)
    If ScriptManager.GetCurrent(Page) IsNot Nothing Then
      Dim scriptManager As System.Web.UI.ScriptManager = System.Web.UI.ScriptManager.GetCurrent(Me.Page)

      ' Register the ASP.NET Button so it triggers a partial postback when clicked.  Note that this
      ' does not need to be done for the Web ADF Callback Button.  This is because all Web ADF
      ' controls are AJAX-enabled, so asynchronous functionality has been wired-up for the callback 
      ' button automatically.
      scriptManager.RegisterAsyncPostBackControl(AspButton)

      If (Not ScriptManager.GetCurrent(Page).IsInAsyncPostBack) Then
        If Me.UserControlTask IsNot Nothing Then
          If (Not String.IsNullOrEmpty(Me.UserControlTask.Configuration)) Then
            FromJsonstring(Me.UserControlTask.Configuration)
          End If
        End If
      End If
    End If
'    #End Region
  End Sub

  'Read of the configuration by parsing JSON string
  Public Sub FromJsonstring(ByVal json As String)
    If String.IsNullOrEmpty(json) Then
      Return
    End If

    Dim xmlhelper As New ESRI.ArcGIS.ADF.XmlHelper()
    Dim decoded As String = xmlhelper.Decode(json)

    Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer()
    Dim deserilizedjson As System.Collections.Generic.IDictionary(Of String, Object) = TryCast(jss.DeserializeObject(decoded), System.Collections.Generic.IDictionary(Of String, Object))
    'set the textbox value by reading the json string from configuration
    If deserilizedjson.ContainsKey("textboxvalue") Then
      TextBox1.Text = TryCast(deserilizedjson("textboxvalue"), String)
    End If
    If deserilizedjson.ContainsKey("color") Then
      UserControlTask.BackColor = System.Drawing.ColorTranslator.FromHtml(TryCast(deserilizedjson("color"), String))
    End If
    Return

  End Sub

  #Region "Executing the task"
  Protected Sub execute_Clicked(ByVal sender As Object, ByVal args As EventArgs)
    MyBase.Start(TextBox1.Text)
  End Sub
  #End Region

  #Region "UserControlTaskPanel Overrides - ExecuteTask"
  Public Overrides Function ExecuteTask(ByVal parameters As Object) As Object
    Dim textBoxValue As String = TryCast(parameters, String)

    System.Threading.Thread.Sleep(500) 'make it look like we're doing some work - ONLY for demo purposes!

    Dim now As DateTime = DateTime.Now
    Dim heading As String = String.Format("The time on the server is {0}:{1:d2}:{2:d2}", now.Hour, now.Minute, now.Second)
    Dim detail As String = String.Format("The value in the text box is: {0}", textBoxValue)

    Dim result As New ESRI.ArcGIS.ADF.Web.UI.WebControls.SimpleTaskResult(heading, detail)
    Return result
  End Function
  #End Region
End Class