Solved

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

Posted on 2011-03-03
2
665 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
2 Comments
 
LVL 35

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 74

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Set cookies HttpOnly and Secure 4 52
Expando 4 34
Showdialog 8 20
Copy/Clone an object. 9 15
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now