Implementing Session
I have a piece of code which loads either french or english text and 2 link buttons that allow t开发者_如何学Goo switch between.
<%
if publierFR = 0 Then
if publierEN = 0 Then
response.write("<p>Aucun texte n'est disponible.</p>")
else
response.write(texteEN)
end if
else
if publierEN = 1 or Session("lang") = "EN" then
%>
<asp:LinkButton OnClick="makeVisibleEN" ID="makeEN" runat="server" visible="false">Version Française</asp:LinkButton>
<asp:LinkButton OnClick ="makeVisibleFR" ID="makeFR" runat="server" visible="true">Version Anglaise</asp:LinkButton>
<%
if makeEN.visible = true then
response.write(texteEN)
else
response.write(texteFR)
end if
elseif publierEN = 0 or Session("lang") = "FR" then
Response.write(texteFR)
end if
end if
%>
What would be an efficient way of displaying the link buttons and text if both English and French exist and the session exists in either EN or FR.
I've thought of using panels to hide the buttons or text, but the main problem is having the page refresh to set the Session variable. Response.redirect(URL)
to refresh the page i suppose and i can't find a better way to display the text other than to Response.write
it since then i'd need a ton of labels.
You should use .NET (and ASP.NET) native localization feature, and just change the culture of the thread that's executing the page. You can still store that culture in the Session if you want (or somewhere else: in a database, in a cookie, in the rendered page, in view state, etc.).
Here are some links on ASP.NET localization:
Best practices for ASP.NET web application localization
Asp.net multilingual web application - localization
精彩评论