Hi,
Here's an image Checkbox I wrote ....
Public Class ImageCheckBox
Inherits WebControl
Implements ICheckBoxControl
Implements IButtonControl
Private handler As ImageCheckBoxClickEventHandler
Public Event CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements ICheckBoxControl.CheckedChanged
Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
Dim image = New Image()
image.ID = Me.ClientID & "_Image"
image.AlternateText = Me.Checked.ToString()
If Not Me.ShowCheckBox Then
MyBase.Style.Add("display", "none")
End If
If Me.Checked Then
image.ImageUrl = Me.CheckedStateImage
Else
image.ImageUrl = Me.UncheckedStateImage
End If
AddHandler Me.ImageCheckBoxClicked, AddressOf OnImageCheckBoxClick
image.RenderControl(output)
MyBase.Render(output)
End Sub
Public Custom Event ImageCheckBoxClicked As ImageCheckBoxClickEventHandler
AddHandler(ByVal value As ImageCheckBoxClickEventHandler)
handler = value
End AddHandler
RemoveHandler(ByVal value As ImageCheckBoxClickEventHandler)
handler = Nothing
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As ImageCheckBoxClickEventArgs)
handler.Invoke(Me, e)
End RaiseEvent
End Event
Public Sub OnImageCheckBoxClick(ByVal sender As Object, ByVal e As ImageCheckBoxClickEventArgs)
RaiseEvent ImageCheckBoxClicked(sender, e)
End Sub
Public Sub OnCheckChanged(ByVal e As EventArgs)
RaiseEvent CheckedChanged(Me, e)
End Sub
<Bindable(True), DefaultValue(0), Description("Specifies Image for the Checked Image"), Category("Appearance")> _
Public Property CheckedStateImage() As String
Get
Dim str As String = DirectCast(Me.ViewState("CheckedStateImage"), String)
If str Is Nothing Then
Return Navigator.ResolveStoreAdminLocation + "images/checked.png"
End If
Return str
End Get
Set(ByVal value As String)
Me.ViewState("CheckedStateImage") = value
End Set
End Property
<Category("Appearance"), Description("Specifies an Image for the UnChecked Image"), Bindable(True), DefaultValue(0)> _
Public Property UncheckedStateImage() As String
Get
Dim str As String = DirectCast(Me.ViewState("UncheckedStateImage"), String)
If str Is Nothing Then
Return Navigator.ResolveStoreAdminLocation + "images/unchecked.png"
End If
Return str
End Get
Set(ByVal value As String)
Me.ViewState("UncheckedStateImage") = value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue(0), Description("Show or hide the checkbox")> _
Public Property ShowCheckBox() As Boolean
Get
If Me.ViewState("ShowCheckBox") Is Nothing Then
Return False
End If
Return CBool(Me.ViewState("ShowCheckBox"))
End Get
Set(ByVal value As Boolean)
Me.ViewState("ShowCheckBox") = value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue(False), Description("Returns the checked state of the control")> _
Public Property Checked As Boolean Implements ICheckBoxControl.Checked
Get
Dim flag As Boolean = CBool(Me.ViewState("Checked"))
If flag.Equals(Nothing) Then
Return False
End If
Return flag
End Get
Set(ByVal value As Boolean)
Me.ViewState("Checked") = value
End Set
End Property
Public Property CausesValidation As Boolean Implements IButtonControl.CausesValidation
Get
Return False
End Get
Set(ByVal value As Boolean)
'MyBase.CausesValidation = value
End Set
End Property
Public Event Click(ByVal sender As Object, ByVal e As System.EventArgs) Implements IButtonControl.Click
Public Event Command(ByVal sender As Object, ByVal e As CommandEventArgs) Implements IButtonControl.Command
Public Sub OnCommand(ByVal sender As Object, ByVal e As CommandEventArgs)
RaiseEvent Command(sender, e)
End Sub
Public Sub OnClick(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim arg = New ImageCheckBoxClickEventArgs(If(Me.Checked, False, True))
OnImageCheckBoxClick(Me, arg)
Me.Checked = arg.Checked
RaiseEvent Click(sender, e)
End Sub
Public Property CommandArgument As String Implements IButtonControl.CommandArgument
Get
Return CStr(Me.ViewState("CommandArgument"))
End Get
Set(ByVal value As String)
Me.ViewState("CommandArgument") = value
End Set
End Property
Public Property CommandName As String Implements IButtonControl.CommandName
Get
Return CStr(Me.ViewState("CommandName"))
End Get
Set(ByVal value As String)
Me.ViewState("CommandName") = value
End Set
End Property
Public Property PostBackUrl As String Implements IButtonControl.PostBackUrl
Get
Return CStr(Me.ViewState("PostBackUrl"))
End Get
Set(ByVal value As String)
Me.ViewState("PostBackUrl") = value
End Set
End Property
Public Property Text As String Implements IButtonControl.Text
Get
Return CStr(Me.ViewState("Text"))
End Get
Set(ByVal value As String)
Me.ViewState("Text") = value
End Set
End Property
Public Property ValidationGroup As String Implements IButtonControl.ValidationGroup
Get
Return CStr(Me.ViewState("ValidationGroup"))
End Get
Set(ByVal value As String)
Me.ViewState("ValidationGroup") = value
End Set
End Property
End Class
Here's the Handler Class
Public Delegate Sub ImageCheckBoxClickEventHandler(ByVal sender As Object, ByVal e As ImageCheckBoxClickEventArgs)
Public Class ImageCheckBoxClickEventArgs
Inherits System.EventArgs
Public Sub New(ByVal Checked As Boolean)
Me.Checked = Checked
End Sub
Private _checked As Boolean
Public Property Checked As Boolean
Get
Return _checked
End Get
Set(ByVal value As Boolean)
_checked = value
End Set
End Property
End Class
Hope this helps!!