Can I have this translated to vb?

public static WebPartCollection GetWebParts(
string path, HttpContext context) {
Page page =
(Page)BuildManager.CreateInstanceFromVirtualPath(
path,
typeof(Page)
);
WebPartCollection webParts = null;
page.PreLoad += delegate {
webParts = WebPartManager.
GetCurrentWebPartManager(page).WebParts;
};
ExecutePage(page, path, context);
return webParts;
}
LVL 9
xav056Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rodmjayCommented:
Public Shared Function GetWebParts(ByVal path As String, ByVal context As HttpContext) As WebPartCollection
    Dim page As Page = DirectCast(BuildManager.CreateInstanceFromVirtualPath(path, GetType(Page)), Page)
    Dim webParts As WebPartCollection = Nothing
    page.PreLoad += Function() Do
        webParts = WebPartManager.GetCurrentWebPartManager(page).WebParts
    End Function
    ExecutePage(page, path, context)
    Return webParts
End Function
0
JoshscorpCommented:
public static WebPartCollection GetWebParts(
string path, HttpContext context) {
Page page =
(Page)BuildManager.CreateInstanceFromVirtualPath(
path,
typeof(Page)
);
WebPartCollection webParts = null;
page.PreLoad += delegate {
webParts = WebPartManager.
GetCurrentWebPartManager(page).WebParts;
};
ExecutePage(page, path, context);
return webParts;
}

from http://www.kamalpatel.net/ConvertCSharp2VB.aspx cheers
0
JoshscorpCommented:
Opps there was a error...ignore the above
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

xav056Author Commented:
online converters are not converting right tried a few of them
0
Bob LearnedCommented:
What version of .NET are you using?  VB.NET 2005 couldn't handle anonymous methods, and I am not sure if 2008 can handle them, either.
0
xav056Author Commented:
Is there a way to achieve the above in a different way by not utilizing anonymous methods?
0
Bob LearnedCommented:
Untested possibility:
Private _WebParts As WebPartCollection = Nothing
 
Public Shared Function GetWebParts(ByVal path As String, ByVal context As HttpContext) As WebPartCollection
    Dim page As Page = DirectCast(BuildManager.CreateInstanceFromVirtualPath(path, GetType(Page)), Page)
    
    AddHandler page.PreLoad, AddressOf OnPagePreLoad
End Function
 
Private Sub OnPagePreLoad(ByVal sender As Object, ByVal e As EventArgs)
    _WebParts = WebPartManager.GetCurrentWebPartManager(page).WebParts
    ExecutePage(page, path, context)
End Sub

Open in new window

0
xav056Author Commented:
nope, doesnt do the trick
0
Bob LearnedCommented:
Attempt #2:

I believe that the page needs to execute first, before the PreLoad is raised:






Private _WebParts As WebPartCollection = Nothing
 
Public Shared Sub GetWebParts(ByVal path As String, ByVal context As HttpContext)
    Dim page As Page = DirectCast(BuildManager.CreateInstanceFromVirtualPath(path, GetType(Page)), Page)
    
    AddHandler page.PreLoad, AddressOf OnPagePreLoad
 
    ExecutePage(page, path, context)
End Function
 
Private Sub OnPagePreLoad(ByVal sender As Object, ByVal e As EventArgs)
    _WebParts = WebPartManager.GetCurrentWebPartManager(page).WebParts
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xav056Author Commented:
Awesome, used to crash doesn't anymore.
Do you mind looking at my other question regarding custom validation on the server side
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.