开发者

How to use Global Varabile in Aspx file?

开发者 https://www.devze.com 2023-02-22 22:40 出处:网络
Say I have a global class: static class GlobalOfficeSetting { public static bool PatientRegistation_DialogOnly = true;

Say I have a global class:

 static class GlobalOfficeSetting 
    {
        public static bool PatientRegistation_DialogOnly = true;

    }

Or let's say if I store the global variable in be开发者_如何学Golow instead:

Application("PatientRegistation_DialogOnly") = true

Then how will I able to call them out in aspx? Because I want to use that as a global setting for all users to on/off display some stuff/functionality in aspx page.

Thanks in advance, King


In the web form code behind:

protected void Page_Load(object sender, EventArgs e)
{
    bool dialogOnly = GlobalOfficeSetting.PatientRegistation_DialogOnly;
    // TODO: use the value
}

or if you decide to use the Application state:

protected void Page_Load(object sender, EventArgs e)
{
    bool dialogOnly = (bool)Application["PatientRegistation_DialogOnly"];
    // TODO: use the value
}

and in the webform itself:

<%= GlobalOfficeSetting.PatientRegistation_DialogOnly %>

or:

<%= (bool)Application["PatientRegistation_DialogOnly"] %>


<%= GlobalOfficeSetting.PatientRegistation_DialogOnly %> should work.


If it is a setting that doesn't change very often, then store it in your web.config file in the settings section.

<appSettings>
    <add key="PatientRegistation_DialogOnly" value="true" />
</appSettings>

and in your code:

bool setting = (bool)ConfigurationManager.AppSettings["PatientRegistation_DialogOnly"];
0

精彩评论

暂无评论...
验证码 换一张
取 消