Setting String to “public” C# Web Developer [close

2019-09-19 12:19发布

So I know there is no such thing as a "global" variable in C# but I am trying to pass a string from my site.master page to a child page. I would like my search button on my master page to pass the value of a textbox on the master page to a "global" string, then have the child page use that "global" string upon page load. What is the best way to approach this?

2条回答
闹够了就滚
2楼-- · 2019-09-19 13:03

Make a class named global and define static variables in it to use them globally.

class Globals
{
    internal static string str_variable;
}

EDIT

when you hit search

Globals.str_variable = Textbox1.Text; 

and when you want to retrieve

string temp = Globals.str_variable;
查看更多
Explosion°爆炸
3楼-- · 2019-09-19 13:10

Go to properties of your project and change the Access Modifier and Scope of the setting, for sample:

enter image description here

查看更多
登录 后发表回答