Help With Drop Down List

570 views
Skip to first unread message

Vb

unread,
Jul 26, 2007, 10:47:48 AM7/26/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Summary: I'm trying to localize a page, by having a drop down where
the user can select the language they want their page translated to.
My means of doing this is creating a Base Page and having all other
pages inherit from their. Similar as to the following posts methods:
http://forums.asp.net/p/969928/1219973.aspx#1219973

Problem: For some reason everytime i choose a language on the drop
down the language, it ends up switching on the page, but for some
reason the drop down always goes back to whatever the first option in
the drop down is.

Meaning: I have a drop down w/options english, italian...i select
italian, page translates to italian, but the drop down shows
english...so basically its just very annoying and nothing more and i
was hoping i could get some help

Here is my code:

BasePage

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Threading;

using System.Globalization;


public class BasePage : Page

{

public BasePage()
{

}

protected override void InitializeCulture()
{

string lang = string.Empty; //default to the invariant culture

HttpCookie cookie = Request.Cookies["SelLang"];if (cookie != null &&
cookie.Value != null)
{

lang = cookie.Value;

Thread.CurrentThread.CurrentUICulture =
CultureInfo.GetCultureInfo(lang);Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(lang);
}

base.InitializeCulture();
}

}

Ascx Page

<asp:DropDownList runat="server" ID="Language1" AutoPostBack="True"
meta:resourcekey="DropDownList1Resource1">

<asp:ListItem Value="auto" Text="Select Language"
meta:resourcekey="ListItemResource7"/>

<asp:ListItem Value="en" Text="English"
meta:resourcekey="ListItemResource1" />

<asp:ListItem Value="de-ch" Text="German"
meta:resourcekey="ListItemResource2" />

<asp:ListItem Value="ja" Text="Japanese"
meta:resourcekey="ListItemResource3" />

<asp:ListItem Value="ru" Text="Russian"
meta:resourcekey="ListItemResource4" />

<asp:ListItem Value="it" Text="Italian"
meta:resourcekey="ListItemResource5" />

<asp:ListItem Value="ar" Text="Arabic"
meta:resourcekey="ListItemResource6" />
</asp:DropDownList>

VB

Protected Sub Language1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Language1.SelectedIndexChanged
If (True) Then

Dim cookie As New HttpCookie("SelLang")
cookie.Value = Language1.SelectedValue

Response.SetCookie(cookie)

'This redirects to the reference page

Response.Redirect(Request.UrlReferrer.AbsoluteUri)

End If

End Sub
End Class

Alexander Higgins

unread,
Jul 27, 2007, 2:13:10 AM7/27/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting

lang = cookie.Value;


Thread.CurrentThread.CurrentUICulture =
CultureInfo.GetCultureInfo(lang);Thread.CurrentThread.CurrentCulture
=
CultureInfo.CreateSpecificCulture(lang);

// Insert sub here to bind the DropDownlist
SetLanguage1(lang)

sub SetLangauge1(lang as string)
dim li as listitem
for each li in Language1.items
if li.text =lang then
li.selected=true
exit sub
end if

end sub

spleenboy

unread,
Jul 26, 2007, 4:32:27 PM7/26/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Try adding this to your InitializeCulture method within the if
(cookie...) statement:

Language1.SelectedValue = lang

Alexander Higgins

unread,
Jul 27, 2007, 3:15:46 PM7/27/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Yeah that'll work to.... Some times the best solutions are the
simplest solutions :)

> > End Class- Hide quoted text -
>
> - Show quoted text -

Vb

unread,
Jul 27, 2007, 4:42:59 PM7/27/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I actually eneded up using the following solution:


Protected Sub Language1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
Language1.SelectedIndexChanged

Dim cookie As New HttpCookie("SelLang")
cookie.Value = Language1.SelectedValue
Response.SetCookie(cookie)

Response.Write("<meta http-equiv='refresh' content='0'>")
Response.End()
End Sub

Reply all
Reply to author
Forward
0 new messages