Sub Calendar
_SelectionChanged(ByVal sender As Object
_
ByVal e As System
EventArgs)
Profile
Info
DateSelected = Calendar
SelectedDate
Profile
Info
LastModified = Now
End Sub
當頁面加載時
我們可以取出預先保存在profile對象中的值
然後再在日歷控件中顯示上次用戶顯示的日期
以及用戶上次選擇日期時的時間
Sub Page_Load(ByVal sender As Object
_
ByVal e As System
EventArgs) Handles Me
Load
Calendar
SelectedDate = Profile
Info
DateSelected
Response
Write(
Date set on
Profile
Info
LastModified)
End Sub
而為了在每次頁面加載時
能根據之前用戶保存在profile對象中的語言正確顯示網頁
必須在page_preinit()事件中寫入如下代碼
Dim lang As System
Globalization
CultureInfo
讀取用戶在下拉框中選取的語言值
Dim selectedLang As String = Request(
ddlLanguage
)
如果用戶選擇auto
則在下拉框中顯示AUTO的選擇項
If selectedLang =
Auto
Then
ddlLanguage
SelectedIndex =
Exit Sub
End If
如果是POSTBACK
則讀取原來已經保存的語言信息
If selectedLang IsNot Nothing Then
lang = New System
Globalization
CultureInfo(selectedLang)
Else
如果是第一次調用頁面
If Profile
language <>
Auto
Then
lang = New System
Globalization
CultureInfo(Profile
language)
Select Case Profile
language
Case
en
US
: ddlLanguage
SelectedIndex =
Case
zh
CN
: ddlLanguage
SelectedIndex =
Case
auto
: ddlLanguage
SelectedIndex =
End Select
Else
if language is auto
then exit
ddlLanguage
SelectedIndex =
Exit Sub
End If
End If
System
Threading
Thread
CurrentThread
CurrentCulture = lang
System
Threading
Thread
CurrentThread
CurrentUICulture = lang
lblWelcomeMessage
Text = Resources
Resource
WelcomeMsg
ToString
Page
Title = Resources
Resource
PageTitle
ToString
lblSelectLanguage
Text = Resources
Resource
SelectLanguage
ToString
下面來解釋一下代碼
首先
聲明一個cultureinfo類型的變量
這個變量將保存用戶每次選擇語言後的信息
[] [] [] []
From:http://tw.wingwit.com/Article/program/net/201311/15160.html