首页 > 解决方案 > 如何在asp.net中声明变量

问题描述

我有一个字符串变量,我在所有页面中都使用了该变量。所以我决定我们声明一个类,并将字符串设置为公共的。在我在一个地方为该变量赋值之后。我在另一个页面中检索字符串变量的值没有出现。所以我需要如何使用公共变量。

Public Class Class1

    Shared _importantData As String
    Public Shared Property ImportantData As String
        Get
            Return _importantData
        End Get
        Set(ByVal value As String)
            _importantData = value
        End Set
    End Property

End Class

在登录页面中,我将值分配给公共变量

Class1.ImportantData = "Data Source=" +  
    ConfigurationManager.AppSettings("DataSource").ToString +  
    ";Initial Catalog=" +  
    ConfigurationManager.AppSettings("InitialCatalog").ToString + 
    ";User ID=" + Session("username") + ";Password=" +  
    ConfigurationManager.AppSettings("Password").ToString + ""

在第二页我检索这样的值

Dim comsd As String = Class1.ImportantData

标签: asp.net

解决方案


推荐阅读