views:

28

answers:

1

Hello all, I am new to this and would like to create a few simple hyperlinks that change the session language parameter.

Then I will test against this parameter to show dynamically different page elements.

I have not been able to find any sort of tutorial discussing a simple solution for this, only full blown tutorials that are in depth with databases and everything.

I was hoping someone here might be able to simply lead me to a beginners tutorial on how to alter the Session language parameter?

Any help appreciated! thanks in advance

+1  A: 

Something along this line?

Thread.CurrentThread.CurrentCulture = new CultureInfo( "pt-BR", false );

You can learn more about it here:

Globalization and localization demystified in ASP.NET 2.0

Edit:

Based on your comment bellow I now understand better what you want to do.

For the link part you can use LinkButton in your .aspx page as:

<asp:LinkButton   id="linkButton1"
                  runat="server"
                  OnCommand="LinkButton1_Click"
                  CommandArgument="pt-BR">Click Me for Portuguese from Brazil
</asp:LinkButton>

Now in your code-behind file .cs:

private void LinkButton1_Click(object sender, System.EventArgs e)
{
    string language = e.CommandArgument.ToString();

    if(language.Equals("pt-BR"))
    {
        // Place your logic here for Portuguese-Brazil... Show or hide DIV...
    } 
}

If you wanna use Session, do this:

To store the value in Session:

private void LinkButton1_Click(object sender, System.EventArgs e)
{
    string language = e.CommandArgument.ToString();

    Session["lang"] = language;
}

To read the value from Session:

if (Session["lang"] != null)
{ 
   if(Session["lang"].ToString().Equals("pt-BR"))
   {
       // Place your logic here for Portuguese-Brazil... Show or hide DIV...
   }
}
Leniel Macaferi
yes this is what I have been seeing on the net alot. I think this is much more than I really need though.Keep in mind I have almost no idea of what I am talking about here but I was thinking something along the lines of this.3 hyperlinks of class "lang" onclick of each would call a simply function that would take for example "es" for spanish and then set the Session("lang") = es.Then in my html I would simply run an if then on the session and If Session is equal to "es" then set certain DIV's visible...Does this make any sense or am I really making it much too simple?
Stefan
Yes... it does make sense. See the edited answer.
Leniel Macaferi
Ok yes this is along the lines of what I am trying to do.However I have two problems, I dont have access to the CodeBehind pages, our programmer keeps a tight grip on them. Also, they are currently written in VB.NET.
Stefan
But what I need to be able to do is write to the Session what language they have selected. That way on each page after, I can use the Session to display the right things.
Stefan
Edited answer once more.
Leniel Macaferi
Oh... you should've tagged your question with VB.NET. Not using codebehind difficult things. I think you can write the method handling within the .aspx using <% %>. It should not be that difficult to translate this code to VB.
Leniel Macaferi
Thank you very much for your help, I think I am on the right path.Just one last question, when working like this am I forced to use a control like that linkButton or could I just use normal HTML Anchor tags and the onClick event to call the function?
Stefan
You'd better use LinkedButton. Using simple anchor tags with asp:hyperlink make things difficult. You'd have to use JavaScript to handle the click as can be seen here: http://www.dotnetfunda.com/articles/article99.aspx
Leniel Macaferi