如何从另一个页面引用变量 [英] How to Reference a variable from another page

查看:115
本文介绍了如何从另一个页面引用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在另一个xaml页面中使用一个变量(由应用程序的用户输入).我怎么做?例如,如果在上一页输入数据,则必须在另一页上禁用某个按钮.

Hi,

I want to use a variable used (that is entered by a user of the application) in another xaml page. How do I do that? For instance if the data entered on the previous page then a certain button must be disabled in another page.

推荐答案

hi,您可以使用查询字符串来完成此操作,或者会议.
例如

在会话中进行一些检查,例如

you can do this by using Query string, or session.
e.g

put some check in the session e.g

session["disablebtn"] = "yes";



然后在加载下一页时,检查一下Page_Load事件
例如



and when the next page is loading put a check on the Page_Load event
e.g

 if(convert.ToString(session["disablebtn"]).Equals("yes"))
{

      //  Disable the Button.
}




如果上述解决方案对您没有帮助,请告诉我.

谢谢




Let me know if the above solution doesn''t help you.

Thanks


如果您正确标记问题,将有所帮助.这是WPF吗?如果两个页面都不是父页面,那么如果您没有直接关系可以调用方法或设置属性,则应设置一个委托,以便在数据更改时可以调用方法告诉此页面更改按钮的状态.我不确定您的上一页"是什么意思,这也许是一头雾水吗?同样的规则也适用,委托是在表单之间进行通信的最佳方式.
If you tag your questions properly, it would help. This is WPF ? If the two pages are not child and parent, if you don''t have a direct relationship where you can call a method or set a property, then you should set up a delegate so that when the data changes, it can call a method telling this page to change the state of the button. I''m not sure what you mean by ''previous page'', is this perhaps silverlight ? The same rule would apply, a delegate is the best way to communicate between forms.


这是WPF页面,在第一页上,我有:
Hi, it''s a WPF Page and on the 1st page I have :
sqlIns = "SELECT [Group] FROM [RIMS_DB].[dbo].[Users] WHERE [UserName] = '" + cbUser.Text + "'AND [Password] = '" + pbPass1.Password + "'";





while (dr.Read())
               {
                      groupUs = dr["group"].ToString();
                      if (groupUs == "Admin")
                     {
                       gbwelcome.Visibility = System.Windows.Visibility.Visible;
                      }


else(groupUs ==& quot; Admin& quot;)
{//等等等等}
}

在第二页上,我要呼叫登录的用户是admin或任何用户,然后禁用某些按钮.


else (groupUs == "Admin")
{// blah blah blah}
}

On the 2nd Page I want to call that user logged in which is an admin or any user then disable certain buttons.


这篇关于如何从另一个页面引用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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