Calling Class from App_Code using vb

S

sck10

Hello,

I am converting a class in the App_Code folder from c# to vb and am having
problems calling the sub procedure. I have created a Sub called HidePanels
in the class "General". When I try to declare a new object of this type in
my codebehind, I get the error: "Type 'HidePanels' is not defined". Any
help with this would be appreciated. Thanks, sck10

code behind
===========
Protected Sub HidePanelAppCode()

Dim HidePanelsHelper As New HidePanels
HidePanelsHelper (Me.Page)

End Sub


App_Code Class
======================
Imports Microsoft.VisualBasic
Public Class General

Public Shared Sub HidePanels(ByVal MyPage As Page)
For Each MasterCtrl As Control In MyPage.Controls
If TypeOf MasterCtrl Is MasterPage Then
For Each FormCtrl As Control In MasterCtrl.Controls
If TypeOf FormCtrl Is HtmlForm Then
For Each ContentCtrl As Control In FormCtrl.Controls
If TypeOf ContentCtrl Is ContentPlaceHolder Then
For Each ChildCtrl As Control In ContentCtrl.Controls
If TypeOf ChildCtrl Is Panel Then
CType(ChildCtrl, Panel).Visible = False
End If
Next
End If
Next
End If
Next
End If
Next
End Sub

End Class
 
W

Walter Wang [MSFT]

Hi,

To access Shared (static in C#) function in VB.NET, use format such as
ClassName.SubName; so you need to use:

General.HidePanels(Me.Page)

#Shared Members in Visual Basic
http://msdn2.microsoft.com/en-us/library/4hbsxy95.aspx

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

sck10

Hi Walter,

I removed the "Shared" so that its now "Public Sub HidePanels(ByVal MyPage
As Page)". It's my understanding that I should be able to call this by
using the following in my codebehind:

Protected Sub ClosePanelAppCode()

' Create instance of the class.
Dim HidePanelsHelper As New HidePanels
HidePanels(Me.Page)

End Sub

However, I am still getting the error: Type 'HidePanels' is not defined.
Thanks, sck10...



App_Code Class
======================
Imports Microsoft.VisualBasic
Public Class General

Public Sub HidePanels(ByVal MyPage As Page)
For Each MasterCtrl As Control In MyPage.Controls
If TypeOf MasterCtrl Is MasterPage Then
For Each FormCtrl As Control In MasterCtrl.Controls
If TypeOf FormCtrl Is HtmlForm Then
For Each ContentCtrl As Control In FormCtrl.Controls
If TypeOf ContentCtrl Is ContentPlaceHolder Then
For Each ChildCtrl As Control In ContentCtrl.Controls
If TypeOf ChildCtrl Is Panel Then
CType(ChildCtrl, Panel).Visible = False
End If
Next
End If
Next
End If
Next
End If
Next
End Sub
 
R

Ray Booysen

sck10 said:
Hi Walter,

I removed the "Shared" so that its now "Public Sub HidePanels(ByVal MyPage
As Page)". It's my understanding that I should be able to call this by
using the following in my codebehind:

Protected Sub ClosePanelAppCode()

' Create instance of the class.
Dim HidePanelsHelper As New HidePanels
HidePanels(Me.Page)

End Sub

However, I am still getting the error: Type 'HidePanels' is not defined.
Thanks, sck10...

Shouldn't
General.HidePanels(Me.Page)
be the method call?
 
W

Walter Wang [MSFT]

Hi,

By removing the "Shared" keyword, it becomes an instance method. So you
need to use <instanceName>.MethodName to call it:

Dim HidePanelsHelper As New HidePanels
HidePanelsHelper.HidePanels(Me.Page)

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Oops, sorry for the typo in previous reply, should be:

Dim HidePanelsHelper As New General
HidePanelsHelper.HidePanels(Me.Page)



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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