• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

get value of private class variable?

how do I get my value from the private class variable?

asp.net page:

<form id="Form1" method="post" runat="server">
<asp:Button id="btnGetInfo" runat="server" Text="Get Info" />
<p>
<asp:TextBox id="txtResults" runat="server" TextMode="MultiLine" Width="256px" Height="80px" />
<p>
<asp:Button id="btnReset" runat="server" Text="Reset" />
</form>
----------------------

code behind:
Imports System
Imports System.Web.HttpRequest
Imports GetInfoWeb.clsGetInfo

Private Sub btnGetInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetInfo.Click
        Dim strDomainName As String
        Dim strServerName As String
        Dim strUserName As String

        strDomainName = GetInfoWeb.clsGetInfo.strDomainName '** error here
        strServerName = Server.MachineName
        strUserName = GetInfoWeb.clsGetInfo.strUserName '** error here

        txtResults.Text = "Domain Name: " & strDomainName & ControlChars.CrLf
        txtResults.Text += "Server Name: " & strServerName & ControlChars.CrLf
        txtResults.Text += "User Name: " & strUserName

End Sub
--------------------

Class file:
Imports System
Public Class clsGetInfo

#Region "Class Variables"
    'variable declarations
    Private strDomainName As String
    Private strUserName As String
#End Region

#Region "Class Properties"
    Public Property DomainName() As String
        Get
            Return Environment.UserDomainName
        End Get
        Set(ByVal Value As String)
            strDomainName = Value
        End Set
    End Property

    Public Property UserName() As String
        Get
            Return Environment.UserName
        End Get
        Set(ByVal Value As String)
            strUserName = Value
        End Set
    End Property
#End Region

End Class
--------------------------------------------

How do I resolve the following errors on the aspx.vb code behind file while trying to get my value from the class file?


Error:
'GetInfoWeb.clsGetInfo.strDomainName' is not accessible in this context because it is 'Private'.
'GetInfoWeb.clsGetInfo.strUserName' is not accessible in this context because it is 'Private'.
0
matthersjr
Asked:
matthersjr
  • 2
  • 2
3 Solutions
 
Jeff CertainCommented:
Well.... "private" means that they're not accessible to anything else... you need to make the variables you want to share with the ASPX page "Protected".
0
 
dharmesh_amityCommented:
You have Public properties access by that

Private Sub btnGetInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetInfo.Click
        Dim strDomainName As String
        Dim strServerName As String
        Dim strUserName As String

        strDomainName = GetInfoWeb.clsGetInfo.DomainName'** error here
        strServerName = Server.MachineName
        strUserName = GetInfoWeb.clsGetInfo.UserName'** error here

        txtResults.Text = "Domain Name: " & strDomainName & ControlChars.CrLf
        txtResults.Text += "Server Name: " & strServerName & ControlChars.CrLf
        txtResults.Text += "User Name: " & strUserName

End Sub
0
 
matthersjrAuthor Commented:
I changed the variables to Protected and the cls properties to protected, but still get errors.

Protected strDomainName As String
Protected strUserName As String

Protected Property DomainName() As String
        Get
            Return Environment.UserDomainName
        End Get
        Set(ByVal Value As String)
            strDomainName = Value
        End Set
    End Property

    Protected Property UserName() As String
        Get
            Return Environment.UserName
        End Get
        Set(ByVal Value As String)
            strUserName = Value
        End Set
    End Property

0
 
dharmesh_amityCommented:
matthersjr,

Keep the Properties publically accessible

Public Property DomainName() As String
        Get
            Return Environment.UserDomainName
        End Get
        Set(ByVal Value As String)
            strDomainName = Value
        End Set
    End Property

    Public Property UserName() As String
        Get
            Return Environment.UserName
        End Get
        Set(ByVal Value As String)
            strUserName = Value
        End Set
    End Property

0
 
matthersjrAuthor Commented:
here is where I'm at now.
vb code behind:
Imports GetInfoWeb.clsGetInfo
        strDomainName = GetInfoWeb.clsGetInfo.DomainName
        strServerName = Server.MachineName
        strOSVersion = GetInfoWeb.clsGetInfo.OSVersion
        strUserName = GetInfoWeb.clsGetInfo.UserName
--------------------------------

class file:
Imports System
Public Shared Property DomainName() As String
        Get
            Return Environment.UserDomainName
        End Get
        Set(ByVal Value As String)
            strDomainName = Value
        End Set
    End Property

    Public Shared Property OSVersion() As String
        Get
            Return Environment.OSVersion.ToString
        End Get
        Set(ByVal Value As String)
            strOSVersion = Value
        End Set
    End Property


    Public Shared Property UserName() As String
        Get
            Return Environment.UserName
        End Get
        Set(ByVal Value As String)
            strUserName = Value
        End Set
    End Property
-------------------------

This works, but I've noticed that the domain name returned is the same as my workstation. I'd like it to return the true domain name, not my workstation name. I did this in vb.net and it works: strDomainName = SystemInformation.UserDomainName

Is systeminformation visible from asp.net?



0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now