本章中还有最后一个可以实际操作的示例并且这将返回到回顾第章中的讨论在第章中和页面样式以及CSS一起您学习了存储主题中的布局和样式首选项的概念可以在每页的基础上切换这些主题如同在第章中讨论的那样然而也可以在用户配置文件中存储有关用户可能倾向于对站点使用哪种主题的数据并且允许用户稍微个人化他们的查看体验在下面的试一试练习中将会在Wrox United应用程序中包括这个功能
()将下面突出显示的代码行添加到FanClubaspx页面
</tr><tr>
<td> Membership Alias:</td>
<td><asp:TextBox ID=txtAlias runat=server />
<asp:RequiredFieldValidator ID=RequiredFieldValidator runat=server ControlToValidate=txtAlias
Text=* ErrorMessage=You must enter a value for the membership alias />
</td>
</tr>
<tr>
<td>Theme:</td>
<td><asp:DropDownList ID=ThemeList runat=server>
<asp:ListItem Text=Default Value= />
<asp:ListItem Text=Wrox Red Value=WroxRed />
<asp:ListItem Text=Wrox Blue Value=WroxBlue />
</asp:DropDownList>
</td>
</tr>
()其他困难的部分是添加一些代码用于在用户的配置文件中存储和检索主题首选项修改FanClubaspxvb将下面突出显示的代码行包括在btnSaveChanges_Click事件处理程序中
Sub btnSaveChanges_Click(ByVal sender As Object ByVal e As SystemEventArgs)
ProfileName = CType(FCLoginViewFindControl(txtName) TextBox)Text
ProfileAddress = CType(FCLoginViewFindControl(txtAddress) TextBox)Text
ProfileCity = CType(FCLoginViewFindControl(txtCity) TextBox)Text
ProfileCounty = CType(FCLoginViewFindControl(txtCounty) TextBox)Text
ProfilePostCode = CType(FCLoginViewFindControl(txtPostCode) TextBox)Text
ProfileCountry = CType(FCLoginViewFindControl(txtCountry) TextBox)Text
ProfileMailings = CType(FCLoginViewFindControl(chkMailing) CheckBox)Checked
ProfileEmail = CType(FCLoginViewFindControl(txtEmail) TextBox)Text
ProfileMemberName = CType(FCLoginViewFindControl(txtAlias) TextBox)Text
ProfileTheme = CType(FCLoginViewFindControl(ThemeList) DropDownList)SelectedValue
ServerTransfer(SiteMapCurrentNodeUrl)
End Sub
()现在修改DisplayProfileProperties方法包括在用户的配置文件中检索和显示当前存储的Theme属性值的代码
Private Sub DisplayProfileProperties()
Dim NameBox As TextBox = CType(FCLoginViewFindControl(txtName) TextBox)
If Not (NameBox Is Nothing) Then
CType(FCLoginViewFindControl(txtName) TextBox)Text = ProfileName
CType(FCLoginViewFindControl(txtAddress) TextBox)Text = ProfileAddress
CType(FCLoginViewFindControl(txtCity) TextBox)Text = ProfileCity
CType(FCLoginViewFindControl(txtCounty) TextBox)Text = ProfileCounty
CType(FCLoginViewFindControl(txtPostCode) TextBox)Text = ProfilePostCode
CType(FCLoginViewFindControl(txtCountry) TextBox)Text = ProfileCountry
CType(FCLoginViewFindControl(chkMailing) CheckBox)Checked = ProfileMailings
CType(FCLoginViewFindControl(txtEmail) TextBox)Text = ProfileEmail
CType(FCLoginViewFindControl(txtAlias) TextBox)Text = ProfileMemberName
CType(FCLoginViewFindControl(ThemeList) DropDownList)SelectedValue = ProfileTheme
End If
End Sub
在这个阶段己经添加所有必要的代码以存储首选项剩下的事情是添加在站点的页面上切换主题的能力
ASPNET 入门教程完整版
[] [] [] [] [] []