Page refresh question

  • Thread starter Thread starter Mark B
  • Start date Start date
M

Mark B

I've got a "Select Language" drop-down on the top-right of the home page.

When I select a new language, the drop-down fires a postback and sets a
cookie and session value for "LanguageSelection". E.g. = "fr-FR"

However after this I still need to press F5 to refresh the webpage before
code in the page uses the new session variable value to display the
different language. Any ideas how to fix this?


Partial Class pages_master_page_MasterPage
Inherits System.Web.UI.MasterPage

Function fSetLanguage() As Boolean

'Check if session language exists
'If not, get cookie, if none, get browser language
'and set cookie and session language

If IsPostBack = False Then
If Session("strLanguageSetting") = Nothing Then
'Get cookie
If Response.Cookies("SiteLanguage").Value = "" Then
Response.Cookies("SiteLanguage").Value =
fGetBrowserLanguage()
End If
Session("strLanguageSetting") =
Response.Cookies("SiteLanguage").Value
End If
DropDownList1.SelectedValue = Session("strLanguageSetting")
End If

End Function

Function fLanguageChange() As Boolean

Session("strLanguageSetting") = DropDownList1.SelectedValue
Response.Cookies("SiteLanguage").Value =
Session("strLanguageSetting")
Response.Cookies("SiteLanguage").Expires =
DateTime.Now.AddDays(1000)

End Function


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
fSetLanguage()
fSetLanguageValues()
End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
fLanguageChange()
End Sub

Function fGetBrowserLanguage() As String

Dim objUserInfo() As String
Dim strBrowserLanguage As String
Dim strWhere As String

objUserInfo = Request.UserLanguages
strBrowserLanguage = objUserInfo(0)

'If an active language then set
strWhere = "LanguageCode='" + strBrowserLanguage + "'"
If SharedFunctions.fGetSingleValueFromTable("Active",
"tblLanguageCodes", strWhere) = True Then
fGetBrowserLanguage = strBrowserLanguage
Exit Function
End If

'If not, regress to root active language, e.g. fr-CA would be fr-FR
strWhere = "LanguageCodeGeneric='" + Left(strBrowserLanguage,
InStr(strBrowserLanguage, "-") - 1) + "' AND [Active]= 'True'"
Dim strFoundLanguageCode As String
strFoundLanguageCode =
SharedFunctions.fGetSingleValueFromTable("LanguageCode", "tblLanguageCodes",
strWhere)
If strFoundLanguageCode <> "" Then
fGetBrowserLanguage = strFoundLanguageCode
Exit Function
End If

'If not active, regress to en-US
fGetBrowserLanguage = "en-US"

End Function

Function fSetLanguageValues() As Boolean

Label1.Text = sfLanguage.fText(30)
Label2.Text = sfLanguage.fText(31)
Label3.Text = sfLanguage.fText(32)
HyperLink1.Text = sfLanguage.fText(33)

End Function

End Class
 
Mark said:
I've got a "Select Language" drop-down on the top-right of the home page.

When I select a new language, the drop-down fires a postback and sets a
cookie and session value for "LanguageSelection". E.g. = "fr-FR"

However after this I still need to press F5 to refresh the webpage
before code in the page uses the new session variable value to display
the different language. Any ideas how to fix this?

Can you just do a Response.Redirect after setting the cookie back to the
same page?
 
Thanks!

That worked:


Function fLanguageChange() As Boolean

Session("strLanguageSetting") = DropDownList1.SelectedValue
Response.Cookies("SiteLanguage").Value =
Session("strLanguageSetting")
Response.Cookies("SiteLanguage").Expires =
DateTime.Now.AddDays(1000)
Response.Redirect(Request.Url.ToString)

End Function
 
Back
Top