Global variables in c#.net

后端 未结 6 1689
长情又很酷
长情又很酷 2020-11-28 05:08

How can I set a global variable in a C# web application?

What I want to do is to set a variable on a page (master page maybe) and access this variable from any page.

6条回答
  •  甜味超标
    2020-11-28 05:27

    Just declare the variable at the starting of a class.

    e.g. for string variable:

    public partial class Login : System.Web.UI.Page
    {
        public string sError;
    
        protected void Page_Load(object sender, EventArgs e)
        {
             //Page Load Code
        }
    

提交回复
热议问题