C# Code in VB

M

Michael Warlich

Hi NG

I'm a noob in ASP.NET and need help!

i have a function in C# which i want to translate in VB.NET
This is C#:

void ShowControlsRecrusiv(Control ctl, string indent)
{
HtmlControl htmldtl = (ctl as HtmlControl);

if(htmlctl != null)
{
Resonse.Write(string.Format("{0} {1}<br>, indent, htmlctl.TagName));

foreach(Control child in ctl.Controls)
ShowControlsRecrusiv(child, indent">");
}
}

And this is VB which i made
Sub ShowControlRecrusiv(ByVal ctrl As Control, ByVal ident As String)

Dim htmlctrl As HtmlControl = ctrl

If Not htmlctrl Is Nothing Then

Response.Write(String.Format("{0} {1}<br>", ident,
htmlctrl.TagName))

End If

Dim cchild As Control

For Each cchild In ctrl.Controls

ShowControlRecrusiv(cchild, ident & ">")

Next

End Sub


but at "Dim htmlctrl As HtmlControl = ctrl" occures the errormessage "The
indicated transformation is invalid."
What can i do?

Thx for Help!

P.S.: I'm german so i hope you understand my english
 
T

tribal

you need to cast control back to HTMLControl

Dim htmldtl As HtmlControl = CType(HtmlControl,
Control)
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top