Setting String to “public” C# Web Developer [closed]

夙愿已清 提交于 2020-01-07 08:27:23

问题


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?


回答1:


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;



回答2:


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



来源:https://stackoverflow.com/questions/19792054/setting-string-to-public-c-sharp-web-developer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!