Reputation: 19
hi i need to use a variables from page to show in another page at text block in windows phone 7. i got a problem that the second page doesn't declare the variables: here's a part of my code:
public static class MainPage : PhoneApplicationPage
{
string result;//var i wanna use at the all application pages
string status;//var i wanna use at the all application pages
string userId;//var i wanna use at the all application pages
string msg;//var i wanna use at the all application pages
WebClient client;
// Constructor
public MainPage()
{
InitializeComponent();
client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
}
///second page
public partial class info : PhoneApplicationPage
{
public info()
{
InitializeComponent();
textBlock1.Text = result.value();
}
}
but this code dosent work ny help??
Upvotes: 1
Views: 348
Reputation: 48985
but this code dosent work
Because your variables are private and their scope is limited to the MainPage
class.
If you want them to be public, you have to add the public
keyword.
Better: you should use properties instead:
public string Result { get; set; }
Also, you can't write a global variable. As C# is an object-oriented programming language, you'll have to use an instance of your MainPage
class to access to your properties:
MainPage myPage = new MainPage();
....
textBlock1.Text = myPage.Result;
Another thing: you're using variables/properties, not functions. So you can't write result.value();
. Use result.value;
instead.
I suggest you to have a look at this MSDN article about properties.
Upvotes: 3
Reputation: 1
As far as I know, you need to declare result variable outside the MainPage class scope or add public keyword
Upvotes: 0