Page refresh question

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
 
L

Leon Mayne

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?
 
M

Mark B

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top