Solved

asp.net vb.net sub in class from another page in project

Posted on 2011-03-03
2
675 Views
Last Modified: 2012-05-11
I have an asp.net web application using VB code behind.  I have created a class to show a message box (trying to learn how to use classes).  I cant seem to figure out how to call the sub within the class.  Everything I have found sudgest that it should be working. I get an error that ShowMessage (name of sub in class) is not a member of WebMsgBox (name of class).  Thanks in advace for the help
***** VB Code Calling Class ******

Public Class UserManagment
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnRun_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRun.Click

        WebMsgBox.ShowMessage("this is a test")
    End Sub
End Class

******* Class Code *******
Public Class WebMsgBox
    Public Class WebMsgBox
        Protected Shared handlerPages As New Hashtable()
        Private Sub New()
        End Sub

        Public Shared Sub ShowMessage(ByVal Message As String)
            If Not (handlerPages.Contains(HttpContext.Current.Handler)) Then
                Dim currentPage As Page = DirectCast(HttpContext.Current.Handler, Page)
                If Not ((currentPage Is Nothing)) Then
                    Dim messageQueue As New Queue()
                    messageQueue.Enqueue(Message)
                    handlerPages.Add(HttpContext.Current.Handler, messageQueue)
                    AddHandler currentPage.Unload, New EventHandler(AddressOf CurrentPageUnload)
                End If
            Else
                Dim queue As Queue = DirectCast(handlerPages(HttpContext.Current.Handler), Queue)
                queue.Enqueue(Message)
            End If
        End Sub

        Private Shared Sub CurrentPageUnload(ByVal sender As Object, ByVal e As EventArgs)
            Dim queue As Queue = DirectCast(handlerPages(HttpContext.Current.Handler), Queue)
            If queue IsNot Nothing Then
                Dim builder As New StringBuilder()
                Dim iMsgCount As Integer = queue.Count
                builder.Append("<script language='javascript'>")
                Dim sMsg As String
                While (iMsgCount > 0)
                    iMsgCount = iMsgCount - 1
                    sMsg = System.Convert.ToString(queue.Dequeue())
                    sMsg = sMsg.Replace("""", "'")
                    builder.Append("alert( """ & sMsg & """ );")
                End While
                builder.Append("</script>")
                handlerPages.Remove(HttpContext.Current.Handler)
                HttpContext.Current.Response.Write(builder.ToString())
            End If
        End Sub
    End Class
End Class

Open in new window

0
Comment
Question by:NCSA SCADA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 250 total points
ID: 35031613
You are defining  Class WebMsgBox twice

Public Class WebMsgBox
    Public Class WebMsgBox

Just use one: (delete the other one)
    Public Class WebMsgBox

Also check that they belong to the same namespace.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 35031618
You have declared a class within a class. You need to refer to both naming levels when trying to call the shared method:
Protected Sub btnRun_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRun.Click

    WebMsgBox.WebMsgBox.ShowMessage("this is a test")
End Sub

Open in new window

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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