熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET 2.0中構造個性化網頁[3]

2022-06-13   來源: .NET編程 
Sub Calendar_SelectionChanged(ByVal sender As Object _
ByVal e As SystemEventArgs)
 ProfileInfoDateSelected = CalendarSelectedDate
 ProfileInfoLastModified = Now
End Sub
  當頁面加載時我們可以取出預先保存在profile對象中的值然後再在日歷控件中顯示上次用戶顯示的日期以及用戶上次選擇日期時的時間

Sub Page_Load(ByVal sender As Object _
ByVal e As SystemEventArgs) Handles MeLoad
CalendarSelectedDate = ProfileInfoDateSelected
 ResponseWrite(Date set on ProfileInfoLastModified)
End Sub
  而為了在每次頁面加載時能根據之前用戶保存在profile對象中的語言正確顯示網頁必須在page_preinit()事件中寫入如下代碼

Dim lang As SystemGlobalizationCultureInfo

讀取用戶在下拉框中選取的語言值
Dim selectedLang As String = Request(ddlLanguage)

如果用戶選擇auto則在下拉框中顯示AUTO的選擇項
If selectedLang = Auto Then
 ddlLanguageSelectedIndex =
 Exit Sub
End If

如果是POSTBACK則讀取原來已經保存的語言信息
If selectedLang IsNot Nothing Then
 lang = New SystemGlobalizationCultureInfo(selectedLang)
Else
如果是第一次調用頁面
If Profilelanguage <> Auto Then
 lang = New SystemGlobalizationCultureInfo(Profilelanguage)
 Select Case Profilelanguage
  Case enUS : ddlLanguageSelectedIndex =
  Case zhCN : ddlLanguageSelectedIndex =
  Case auto : ddlLanguageSelectedIndex =
 End Select
Else
 if language is auto then exit
 ddlLanguageSelectedIndex =
 Exit Sub
End If
End If

SystemThreadingThreadCurrentThreadCurrentCulture = lang
SystemThreadingThreadCurrentThreadCurrentUICulture = lang

lblWelcomeMessageText = ResourcesResourceWelcomeMsgToString
PageTitle = ResourcesResourcePageTitleToString
lblSelectLanguageText = ResourcesResourceSelectLanguageToString
  下面來解釋一下代碼首先聲明一個cultureinfo類型的變量這個變量將保存用戶每次選擇語言後的信息

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15160.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.