将字符串设置为“公共". C#Web开发人员 [英] Setting String to "public" C# Web Developer

查看:93
本文介绍了将字符串设置为“公共". C#Web开发人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我知道C#中没有诸如全局"变量之类的东西,但我正在尝试将字符串从我的site.master页面传递给子页面.我希望我的母版页上的搜索按钮将母版页上文本框的值传递给全局"字符串,然后让子页面在页面加载时使用该全局"字符串.解决此问题的最佳方法是什么?

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?

推荐答案

创建一个名为global的类,并在其中定义静态变量以全局使用它们.

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

class Globals
{
    internal static string str_variable;
}

编辑

点击搜索时

Globals.str_variable = Textbox1.Text; 

以及要检索的时间

string temp = Globals.str_variable;

这篇关于将字符串设置为“公共". C#Web开发人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆