www.webdeveloper.com
Results 1 to 4 of 4

Thread: Why isn't this class working?

  1. #1
    Join Date
    Jul 2004
    Posts
    43

    Why isn't this class working?

    I'm using ASP.NET (VB), and I'm trying to use a class to display a custom popup function (alert().

    Code:
    Public Class msgClass
        Inherits System.Web.UI.Page
        Public Shared Sub alert(ByVal msg As String)
            Response.Write("<script>alert('" + msg.tostring + "');</script>")
        End Sub
    End Class
    The problem here is that is says I need an explicit instance of a class to use response. (Not sure how to do that...)

    This is how I call it in my main ASPX.vb page:

    Code:
                    Dim a As New msgClass
                    a.alert(IsDate(txtStartDate.Text).ToString)
    I've tried using Public Sub, but when it gets there, it tells me that "response..." can't be used like that.
    Last edited by MdWebtress; 12-07-2004 at 03:20 PM.

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224

  3. #3
    Join Date
    Jul 2004
    Posts
    43
    Ok, I've gotten it like this:

    Code:
    Namespace Properties
        Public Class a
            Inherits System.Web.UI.Page
            Private a As Integer
            Private str As String
            Public Property setInt() As Integer
                Get
                    Return a
                End Get
                Set(ByVal Value As Integer)
                    a = Value
                End Set
            End Property
            Public Property setStr() As String
                Get
                    Return str
                End Get
                Set(ByVal Value As String)
                    str = Value
                End Set
            End Property
            Public Sub Message(ByVal str As String)
                Response.Write("<script>alert('" + a.ToString + "');</script>")
            End Sub
        End Class
    End Namespace
    I can call the Message() sub, but I get the error that: "Response is not available in this context. ". If I put in "Shared sub" I can't use it. ("Can't refer to an instance member of a class from within a shared method....")
    Last edited by MdWebtress; 12-08-2004 at 09:30 AM.

  4. #4
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    What I mean rather, are you importing that namespace on the head of your asp.net page?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles