本章中還有最後一個可以實際操作的示例並且這將返回到回顧第章中的討論在第章中和頁面樣式以及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 入門教程完整版
[] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/net/201311/15606.html