Implementing IPostBackEventHandler


M

Mechanic

http://mikekappel.com/examples/VB/CustomControls/Image.vb

I am trying to figure out why the postback event does not fire. Anyone
know?

Imports Microsoft.VisualBasic
Imports System.Web.UI

''' <summary>
''' MikeImage is a Javascript enabled Custom Control
''' Automatic Javascipt Rollovers
''' </summary>
''' <remarks></remarks>
Public Class MikeImage
Inherits Image
Implements IPostBackEventHandler

''' <summary>
''' Define the Click event.
''' </summary>
''' <remarks></remarks>
Public Event Click As EventHandler

''' <summary>
''' Invoke delegates registered with the Click event.
''' </summary>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub

''' <summary>
''' Url of the Rollover image
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ImageUrlOver() As String
Get
Return _ImageUrlOver
End Get
Set(ByVal value As String)
_ImageUrlOver = value
End Set
End Property
Private _ImageUrlOver As String = ""

''' <summary>
''' Javascript OnMouseOver Event
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property OnClientMouseOver() As String
Get
Return _OnClientMouseOver
End Get
Set(ByVal value As String)
_OnClientMouseOver = value
End Set
End Property
Private _OnClientMouseOver As String = ""

''' <summary>
''' Javascript OnMouseOut Event
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property OnClientMouseOut() As String
Get
Return _OnClientMouseOut
End Get
Set(ByVal value As String)
_OnClientMouseOut = value
End Set
End Property
Private _OnClientMouseOut As String = ""

''' <summary>
''' Javascript OnClick Event
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property OnClientClick() As String
Get
Return _OnClientClick
End Get
Set(ByVal value As String)
_OnClientClick = value
End Set
End Property
Private _OnClientClick As String = ""

''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property HRef() As String
Get
Return _HRef
End Get
Set(ByVal value As String)
_HRef = value
End Set
End Property
Private _HRef As String = ""

''' <summary>
''' Loads Javascript into Image HTML markup
''' </summary>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Overrides Sub OnPreRender(ByVal e As
System.EventArgs)
OnClientClick +=
Me.Page.ClientScript.GetPostBackEventReference(Me, "Click")

If ImageUrlOver <> "" Then OnClientMouseOver =
"this.src='" + ImageUrlOver + "';" + OnClientMouseOver
If ImageUrlOver <> "" Then OnClientMouseOut = "this.src='"
+ ImageUrl + "';" + OnClientMouseOut
If OnClientMouseOver <> "" Then Me.Attributes.Add
("onmouseover", OnClientMouseOver)
If OnClientMouseOut <> "" Then Me.Attributes.Add
("onmouseout", OnClientMouseOut)
If OnClientClick <> "" Then Me.Attributes.Add("onclick",
OnClientClick)
MyBase.OnPreRender(e)
End Sub

''' <summary>
''' Define the method of IPostBackEventHandler that raises
change events.
''' </summary>
''' <param name="eventArgument"></param>
''' <remarks></remarks>
Public Sub RaisePostBackEvent(ByVal eventArgument As String) _
Implements IPostBackEventHandler.RaisePostBackEvent
If HRef <> "" AndAlso eventArgument Is "Click" Then
HttpContext.Current.Response.Redirect(HRef)
Me.OnClick(EventArgs.Empty)
End If
End Sub
End Class
 
Ad

Advertisements

Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top