c# - reading from text box and passing to another page -
i want read text textbox , send page. on page keep geting empty string. why doesn't work ?
i have on page 1:
public string _beseda() { return textbox1.text; }
and on page 2 should retrieve string:
private void button1_click(object sender, routedeventargs e) { page2 neki = new page2(); messagebox.show(neki._beseda()); }
there 2 strategies pass data between pages in windows phone.
- use app.cs
- pass data parameter values during navigation
1. using app.cs
open app.cs code behind of app.xaml write:
// store textbox value public string storevalue;
in page1
protected override void onnavigatedfrom(system.windows.navigation.navigationeventargs e) { base.onnavigatedfrom(e); app app = application.current app; app.storevalue = textbox1.text; }
on page2
private void button1_click(object sender, routedeventargs e) { app app = application.current app; messagebox.show(app.storevalue); }
2. passing values parameters while navigating
before navigating embed textbox value page url
string newurl = "/page2.xaml?text="+textbox1.text; navigationservice.navigate(new uri(newurl, urikind.relative));
in page2
//temporarily hold value got navigation string textboxvalue = ""; protected override void onnavigatedto(system.windows.navigation.navigationeventargs e) { base.onnavigatedto(e); //retrieve value passed during page navigation navigationcontext.querystring.trygetvalue("text", out textboxvalue) } private void button1_click(object sender, routedeventargs e) { messagebox.show(textboxvalue); }
here number of useful links..
Comments
Post a Comment