i.e i have a header ascx file, and the title can be in 2 languages, the data is picked out of a db, so what i want to do is generate the sql string based on a variable that is defined from a hypelink within in another ascx file. But both these files will be common inside an/each aspx file.
Any ideas/suggestion? (I assume this is possible).
Thanks in advance.
DeianActually, you don't need to keep track of this kind of information on your own; HTTP requests include an 'Accept-Language' header which contains a setting for the language content the user prefers. (If the user is using Internet Explorer, she can set this from the Genral tab in Internet Options by clicking the 'Languages' button.)
The code for extracting this information on a Page would look like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ci As System.Globalization.CultureInfo
Dim FullName As StringTry
ci = New System.Globalization.CultureInfo(Request.UserLanguages(0))
FullName = ci.EnglishName
Catch
' CultureInfo only supports a subset of all valid language identifiers, so the above
' might fail for some languages.
FullName = Request.UserLanguages(0)
End TryLabel1.Text = FullName
End Sub
On a UserControl, you would need to replace 'Request' with 'Context.Request' to get to the same information.
Hope this helps,
> Any ideas/suggestion? (I assume this is possible).
Yes, it's possible.
I've put up a sample for you atwww.edition3.com/developers/deiwales
The boxes show the two separate user controls.
The code can be downloaded fromwww.edition3.com/developers/deiwales/code.zip
For anyone following this thread later, here's the code:
ASPX Page:
<%@. Page Language="VB" %>
<%@. Register TagPrefix="my" TagName="UserControlA" src="http://pics.10026.com/?src=mycontrol7.ascx" %>
<%@. Register TagPrefix="my" TagName="UserControlB" src="http://pics.10026.com/?src=mycontrol7b.ascx" %>
<script runat="server"
Sub UserControlB_Click( ByVal sender As Object, ByVal eArgs As EventArgs )
UserControlA.SetLanguage( UserControlB.Language )
End Sub</script>
<html>
<head>
</head>
<body>
<form runat="server">
<div style="border: solid 1px silver;padding: 20px;">
<my:UserControlB id="UserControlB" onclick="UserControlB_Click" runat="server" />
</div>
<div style="border: solid 1px silver;padding: 20px;">
<my:UserControlA id="UserControlA" runat="server" />
</div>
</form>
</body>
</html>
UserControlA (to display language):
<%@. Control Language="VB" %>
<script runat="server"
Sub Page_Load( sender As Object, eArgs As EventArgs )
If Not Page.IsPostBack Then
SetLanguage( "English" )
End If
End SubPublic Sub SetLanguage( Which As String )
If Which = "French" Then
Message.Text = "Bonjour, je suis"
Else
Message.Text = "Hello, I am"
End If
End Sub</script>
<asp:Label id="Message" runat="server" /> UserControlA.ascx
UserControlB (to set the language):
<%@. Control Language="VB" %>
<script runat="server"
Public Language As StringPublic Event Click(ByVal sender As Object, ByVal eArgs As EventArgs)
Sub Submit_Click( ByVal sender As Object, ByVal eArgs As EventArgs )
' set the language
Language = SelectedLanguage.SelectedItem.Text
' raise the event, so that our ASPX page can handle it
RaiseEvent Click( Me, EventArgs.Empty )
End SubProtected Overrides Function OnBubbleEvent(ByVal sender As Object, ByVal eArgs As System.EventArgs) As Boolean
' and now bubble it up
RaiseBubbleEvent(sender, eArgs)
End Function</script>
<asp:RadioButtonList id="SelectedLanguage" runat="server">
<asp:ListItem text="English" selected="True" />
<asp:ListItem text="French" />
</asp:RadioButtonList>
<asp:Button id="Submit" text="Submit" onclick="Submit_Click" runat="server" />
Good stuff... that clarifies it.
But as for the internal support for the language ye that won't work cos my idea is to do web sites in english and provide welsh language translation at the touch of a button. So in the db the data will be held, and the string will be used to decide the logic for the sql string. Hope that clairfies my scenario.
The DB.Table is done in a way that holds data and cssstyles against page number, language and content type, and the id of everything will be generated out of the cirteria that define the content/style.
Thanks guys.
0 comments:
Post a Comment