Common Custom renderers
Common_CustomRenderers_VBNet\LabelPointRenderer.aspx.vb
' Copyright 2010 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
Public Partial Class LabelPointRendererPage
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    If (Not ScriptManager1.IsInAsyncPostBack) Then
      ' Potential inital load. Check if graphics resource has the graphics layer, and if not, create it
      Dim mapResourceItem As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem = MapResourceManager1.ResourceItems.Find("GraphicsDataSource")
      Dim graphicsMapResource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource = TryCast(mapResourceItem.Resource, ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)

      If Not graphicsMapResource Is Nothing Then
        ' Check whether the map extent is null, meaning the map has not yet been initialized
        If Map1.Extent Is Nothing Then
          ' Forces earlier initialization of map and will set map extent
          Dim primaryMapResource As ESRI.ArcGIS.ADF.Web.DataSources.IMapResource = Map1.PrimaryMapResourceInstance
        End If

        ' Call helper method in App_Code which generates a random graphics layer.  In real-world situations,
        ' the random layer could be replaced with, for instance, the result of a query.  Once the layer is
        ' created, apply the renderer and add the layer to the graphics resource.

        Dim featureGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer = ESRI.ADF.Samples.Renderers.GenerateGraphicsHelper.CreatePointFeatures("points", Map1.Extent, 50)

        If Not featureGraphicsLayer Is Nothing Then
          ' Apply the LabelPointRenderer to the graphics layer
          Dim renderer As ESRI.ADF.Samples.Renderers.LabelPointRenderer = New ESRI.ADF.Samples.Renderers.LabelPointRenderer()
          renderer.LabelColumn = "RandomName" ' Name of column that contains the label text
          renderer.BackgroundColor = System.Drawing.Color.FromArgb(255, 255, 255, 200)
          featureGraphicsLayer.Renderer = renderer ' Assign renderer

          ' If a layer of the same name has already been added, remove it
          If graphicsMapResource.Graphics.Tables.Contains("points") Then
            graphicsMapResource.Graphics.Tables.Remove("points")
          End If

          ' Add the layer to the graphics resource
          graphicsMapResource.Graphics.Tables.Add(featureGraphicsLayer)
        End If
      End If

      ' Refresh the graphics resource so the newly added layer shows up
      Map1.RefreshResource("GraphicsDataSource")
    End If
  End Sub

End Class