Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Can I have this translated to vb?

Posted on 2008-11-17
10
Medium Priority
?
311 Views
Last Modified: 2012-05-05
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;
}
0
Comment
Question by:xav056
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 8

Expert Comment

by:rodmjay
ID: 22979506
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
 

Expert Comment

by:Joshscorp
ID: 22980421
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
 

Expert Comment

by:Joshscorp
ID: 22980431
Opps there was a error...ignore the above
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Author Comment

by:xav056
ID: 22980830
online converters are not converting right tried a few of them
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 23035117
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
 
LVL 9

Author Comment

by:xav056
ID: 23183212
Is there a way to achieve the above in a different way by not utilizing anonymous methods?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 23184034
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
 
LVL 9

Author Comment

by:xav056
ID: 23206359
nope, doesnt do the trick
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 23206522
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
 
LVL 9

Author Comment

by:xav056
ID: 23206896
Awesome, used to crash doesn't anymore.
Do you mind looking at my other question regarding custom validation on the server side
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question