使用独立存储的IsolatedStorageSettings对象进行页面间传值
2010-08-11 16:29
543 查看
在asp.net开发中页面间的传值方法有很多种,如Session、Cookie等技术,但是在Silverlight中,我们可以通过IsolatedStorageSettings这个独立存储对象来实现。
(1)、首先需要在每个需要使用传递过来的值的页面中添加命名空间:using System.IO.IsolatedStorage;
(2)、如在Login.xaml页面中,首先创建一个IsolatedStorage对象,如下:
//使用独立存储的IsolatedStorageSettings对象
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
(3)、在登录按钮事件中,验证通过并跳转的语句后面添加如下类似于Session的用于保存用户信息,并可以在其他页面中读取该值。
...
if (!appSettings.Contains("uname"))
{
appSettings.Add("uname", this.tbUserName.Text.Trim());
}
...
(4)、在MainPage.xaml页面中,首先创建一个IsolatedStorageSettings对象,然后利用此对象来读取保存的用户信息。
...
//使用独立存储的IsolatedStorageSettings对象
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
...
if(appSettings.Contains("uname"))
{
this.tbUserName.Text = appSettings["uname"].ToString();
}
(1)、首先需要在每个需要使用传递过来的值的页面中添加命名空间:using System.IO.IsolatedStorage;
(2)、如在Login.xaml页面中,首先创建一个IsolatedStorage对象,如下:
//使用独立存储的IsolatedStorageSettings对象
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
(3)、在登录按钮事件中,验证通过并跳转的语句后面添加如下类似于Session的用于保存用户信息,并可以在其他页面中读取该值。
...
if (!appSettings.Contains("uname"))
{
appSettings.Add("uname", this.tbUserName.Text.Trim());
}
...
(4)、在MainPage.xaml页面中,首先创建一个IsolatedStorageSettings对象,然后利用此对象来读取保存的用户信息。
...
//使用独立存储的IsolatedStorageSettings对象
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
...
if(appSettings.Contains("uname"))
{
this.tbUserName.Text = appSettings["uname"].ToString();
}
相关文章推荐
- 在wp7独立存储IsolatedStorageSettings里保存对象时,对象要序列化
- WindowsPhone开发 +使用Live SDK相关API操作SkyDrive + IsolatedStorageSettings的Bug。
- Storyboard使用TableView进行页面跳转传值
- 使用sessionStorage实现页面间传值与传对象
- 使用plist进行页面间传值
- Windows phone 7中,把页面数据存为长期存储(非IsolatedStorageFile),而是用IsolatedStorageSettings
- Storyboard使用TableView进行页面跳转传值
- 使用delegate进行页面间传值
- 使用javascript进行页面间传值的问题
- 使用jsp的forward指令进行页面跳转时注意session对象的清除
- 使用Block来进行页面间的传值
- 使用Server.Transfer进行页面间传值
- 使用XMLHttprequest对象进行异步调用html页面的示例
- Fckeditor增加自定义工具栏(ToolbarSet)及FCKeditor对象在页面的使用
- 使用Block实现页面传值
- ASP.NET页面传值不使用QueryString
- HTML5 使用 sessionStorage 进行页面传值
- 页面传值避免使用"ID"
- 使用ab进行页面的压力测试
- 使用Hibernate进行对象的关系映射