CSharp to VB.Net (aspx page)

C

Chris

In C# I can do:
((Page)this.Parent).Title = "Title"

Why doesn't this work in VB:
DirectCast(me.Parent, Page).Title = "Title"


The Title var doesn't show up in VB.

Thanks.
Chris
 
K

Kevin Spencer

Use CType(me.Parent, Page).Title = "Title"

The diffeence is the CType will convert to any type that can be converted to
the type. DirectCast only casts the type if the type is exactly the same.
Since your Page class is not System.Web.UI.Page, but a derived class with a
different name, DirectCast will fail unless you cast it to the exact type of
your page class.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
 
C

Chris

Kevin said:
Use CType(me.Parent, Page).Title = "Title"

The diffeence is the CType will convert to any type that can be converted to
the type. DirectCast only casts the type if the type is exactly the same.
Since your Page class is not System.Web.UI.Page, but a derived class with a
different name, DirectCast will fail unless you cast it to the exact type of
your page class.


I'm sorry but I have to disagree with you.

This code converts the object to a Page object
((Page)this.Parent).Title

So does this code.
DirectCast(me.Parent, Page).Title

The problem isn't the casting to a page object, the code isn't failing
at design time cause of a miscast. The problem is that it says the page
object doesn't have a title property on it.

My real question is:
Page.Title exists in C# but not in VB? What am I not doing in VB to get
the page.title property.

Chris
 

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,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top