T
Ty
Hello all,
I am creating a website in VS 2008 VB.net. On one of my pages I am
using the Table control to make a type of calendar a IN/OUT board.
The problem I found after I wrote all the code to create the table was
that there is not Cell Click event. So I did some looking and asked
around and got this C# (see below) version of a class that someone
built to create a clickable cell.
The issue is that even though I got it converted it seems to have
syntax issues and I'm not very familiar with classes or custom events
(see VB conversion below).
Any help woulld be greatful.
C# CODE
public class ClickableTableCell : TableCell, IPostBackEventHandler
{
public ClickableTableCell()
{
this.Attributes.Add("onmouseover", "this.style.cursor='hand'");
}
private static readonly object EventClick = new object();
public event EventHandler Click
{
add
{
Events.AddHandler(EventClick,
value);
}
remove
{
Events.RemoveHandler(EventClick,
value);
}
}
protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;
if (h != null)
h(
this, e);
}
#endregion
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(
EventArgs.Empty);
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(
HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(this, "lbl"));
}
}
**********************************************************************************************************************************
VB CONVERTED CODE
Imports Microsoft.VisualBasic
Public Class ClickableTableCell
Inherits TableCell
Implements IPostBackEventHandler
Public Sub New()
Me.Attributes.Add("onmouseover", "this.style.cursor='hand'")
End Sub
Private Shared ReadOnly EventClick As New Object()
Public Custom Event Click As EventHandler
AddHandler(ByVal value As EventHandler)
Events.[AddHandler](EventClick, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
Events.[RemoveHandler](EventClick, value)
End RemoveHandler
End Event
Protected Sub OnClick(ByVal e As EventArgs)
Dim h As EventHandler = TryCast(Events(EventClick),
EventHandler)
RaiseEvent h(Me, e)
End Sub
Private Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
If eventArgument = "lbl" Then
OnClick(EventArgs.Empty)
End If
End Sub
Protected Overloads Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
End Sub
End Class
Thanks,
Ty
I am creating a website in VS 2008 VB.net. On one of my pages I am
using the Table control to make a type of calendar a IN/OUT board.
The problem I found after I wrote all the code to create the table was
that there is not Cell Click event. So I did some looking and asked
around and got this C# (see below) version of a class that someone
built to create a clickable cell.
The issue is that even though I got it converted it seems to have
syntax issues and I'm not very familiar with classes or custom events
(see VB conversion below).
Any help woulld be greatful.
C# CODE
public class ClickableTableCell : TableCell, IPostBackEventHandler
{
public ClickableTableCell()
{
this.Attributes.Add("onmouseover", "this.style.cursor='hand'");
}
private static readonly object EventClick = new object();
public event EventHandler Click
{
add
{
Events.AddHandler(EventClick,
value);
}
remove
{
Events.RemoveHandler(EventClick,
value);
}
}
protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;
if (h != null)
h(
this, e);
}
#endregion
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(
EventArgs.Empty);
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(
HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(this, "lbl"));
}
}
**********************************************************************************************************************************
VB CONVERTED CODE
Imports Microsoft.VisualBasic
Public Class ClickableTableCell
Inherits TableCell
Implements IPostBackEventHandler
Public Sub New()
Me.Attributes.Add("onmouseover", "this.style.cursor='hand'")
End Sub
Private Shared ReadOnly EventClick As New Object()
Public Custom Event Click As EventHandler
AddHandler(ByVal value As EventHandler)
Events.[AddHandler](EventClick, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
Events.[RemoveHandler](EventClick, value)
End RemoveHandler
End Event
Protected Sub OnClick(ByVal e As EventArgs)
Dim h As EventHandler = TryCast(Events(EventClick),
EventHandler)
RaiseEvent h(Me, e)
End Sub
Private Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
If eventArgument = "lbl" Then
OnClick(EventArgs.Empty)
End If
End Sub
Protected Overloads Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
End Sub
End Class
Thanks,
Ty