Solved

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

Posted on 2011-03-03
2
673 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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