Help with C# class to VB.net conversion.

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
 
D

David Anton

The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
'...
End RaiseEvent

Other than that your conversion looks good.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI


Ty said:
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
 
T

Ty

The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '...
End RaiseEvent

Other than that your conversion looks good.
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI



Ty said:
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.
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
{







protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;
if (h != null)
h(
this, e);
}

void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(

protected override void AddAttributesToRender(HtmlTextWriter writer)
{

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

Ty- Hide quoted text -

- Show quoted text -

Hello David,

The problem is that I'm not quite sure how to change that event block.
If you look at the line Public Custom Event Click As EventHandler. VS
has "Click" underline and it says that the 'RaiseEvent' definition
missing for event "Click". I cannot seem to get it right no matter
what I try.

Also lower in the code in the Protected Sub OnClick(ByVal e As
EventArgs) block the line RaiseEvent h(Me, e). The "h" is underlined
and is says 'h' is not an event of "ClickableTableCell". I have no
idea what to do with that.

Thanks,
Ty
 
D

David Anton

Here's a link which gives a sample of what the RaiseEvent block should contain:
http://www.codeguru.com/vb/gen/vb_general/idelanguage/article.php/c9481
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI


Ty said:
The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
'...
End RaiseEvent

Other than that your conversion looks good.
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI



Ty said:
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.
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
{







protected void OnClick(EventArgs e)
{
EventHandler h = Events[EventClick] as EventHandler;
if (h != null)
h(
this, e);
}

void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "lbl")
OnClick(

protected override void AddAttributesToRender(HtmlTextWriter writer)
{

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)
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)

writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
Page.ClientScript.GetPostBackEventReference(Me, "lbl"))
End Sub
End Class

Ty- Hide quoted text -

- Show quoted text -

Hello David,

The problem is that I'm not quite sure how to change that event block.
If you look at the line Public Custom Event Click As EventHandler. VS
has "Click" underline and it says that the 'RaiseEvent' definition
missing for event "Click". I cannot seem to get it right no matter
what I try.

Also lower in the code in the Protected Sub OnClick(ByVal e As
EventArgs) block the line RaiseEvent h(Me, e). The "h" is underlined
and is says 'h' is not an event of "ClickableTableCell". I have no
idea what to do with that.

Thanks,
Ty
 
T

Ty

Here's a link which gives a sample of what the RaiseEvent block should contain:http://www.codeguru.com/vb/gen/vb_general/idelanguage/article.php/c9481
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI



Ty said:
The custom event in VB must implement a 'RaiseEvent' block:
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '...
End RaiseEvent
Other than that your conversion looks good.
--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
:
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- Hide quoted text -
- Show quoted text -
Hello David,
The problem is that I'm not quite sure how to change that event block.
If you look at the line Public Custom Event Click As EventHandler. VS
has "Click" underline and it says that the 'RaiseEvent' definition
missing for event "Click". I cannot seem to get it right no matter
what I try.
Also lower in the code in the Protected Sub OnClick(ByVal e As
EventArgs) block the line RaiseEvent h(Me, e). The "h" is underlined
and is says 'h' is not an event of "ClickableTableCell". I have no
idea what to do with that.
Thanks,
Ty- Hide quoted text -

- Show quoted text -

Hello all,

David thanks for you help. I got the answer from my original post
although I was not expecting it. See here for the answer.
http://forums.asp.net/p/1303134/2551012.aspx#2551012
 

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