Take labels name ???

G

Giovane Calabrese

( aspx + vb )
hi everyone !
I really need make that function work !
im brazilian , and i want to make a multilanguage system ,
that function above must look at all ASPX take the labels
ID and send as a parameter
,... so Please , help me ,.. cause it doest work !

'----------------------------------------------------------
--------------
' LOAD PAGE
'----------------------------------------------------------
--------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
TraduzLbl(me)

end sub

Sub TraduzLbl(byval parent As Control)
Dim XmlLang1 as new XmlLang
Dim varxml as string
Dim c As Control

For each c In parent.Controls
If c.GetType() is GetType(system.web.ui.webcontrols.Label)
Then
varxml = CType(c,system.web.ui.webcontrols.Label).text
CType(c,system.web.ui.webcontrols.Label).text =
XmlLang1.GetString(varxml)

End If

Next
End Sub
 
J

JezB

I do something very similar with all labels on a page (though I only use c#
so the vb code is difficult for me to follow!). May I ask what actually
happens when you run this ? My first thought is that you must make the
routine recursive by calling itself on each sub-control within each top
level control on the page.
 
G

Giovane Calabrese

ok. im try to make a multilanguage system based on that
tutorial :

http://www.123aspx.com/redir.aspx?res=29112

in my aspx pages all text are in labels , and i want to
take the name labels ( in one loop ) and for each label
take on the XML document the right(in the right language)
Value (text).

Above you can see what im doing , it works , however im
trying to make a function that look at all aspx and when
found a LABEL , take the value ( text) from one xml
document like the function in the end of this document.
**********************************************************

I have created an object that will retrieve the correct
data from an XML file. The code in C# is displayed below.
------------------------------------------------------
using System;
using System.Xml;


namespace diffudessnet
{
public class XmlLang
{
protected XmlDataDocument X;
protected String Lang;


public XmlLang(String FileName,String
Language)
{
String Name
= "http://localhost/myapp/xml/"+ FileName;
X = new XmlDataDocument();
X.Load(Name);
Lang = Language;
}



public XmlLang(String FileName)
{
String Name
= "http://localhost/myapp/xml/"+ FileName;
X = new XmlDataDocument();
X.Load(Name);
Lang = "N";
}


public String GetString(String Name)
{
XmlNode node;
node = X.SelectSingleNode
("//main/language[@id='" +Lang + "']/" + Name);
if (node == null) return "";
else
{
string value =
node.InnerXml.ToString();
return value;
}
}
}
}

------------------------------------------------------

This object has three methods:

XmlLang::XmlLang(String FileName, String Language)
XmlLang::XmlLang(String FileName)
String XmlLang::GetString(String Name)
To start, we will assume all XML documents are in the same
directory. In this way, they can be made inaccessible to
all users. The path of this directory is hardcoded in the
source of the object. A good alternative is using the
ConfigurationSettings.AppSettings method and saving all
values in the web.config file.

In the first version of the constructor, the name of the
XML file and the selected language are passed to the
constructor. If you want to select a name for the
document, it might be useful to select the same name as
you aspx file. The language parameter is a simple string.
Possible values are "N" for Dutch, "F" for French, "E" for
English, . The format of the XML document will be
discussed later.

The second version of the constructor will automatically
select the Dutch version of the texts. This option is very
handy if you only want to use the Dutch version, and other
languages are only planned for the future.

The method GetString(String Name) will retrieve the text
belonging to the node named Name from the XML file. All
text items in the XML document are marked by keywords. The
value of a keyword is the word in the specified language.
-------------------------------------------
XML Document
<?xmlversion="1.0"encoding="utf-8"?>
<main>
< language id ="N">
<name>Naam</ name>
<number>Nummer</number>
<street>Straat</street>
<country>Land</country>
</ language >
< language id ="E">
<name>Name</name>
<number>Number</number>
<street>Street</street>
<country>Country</country>
</language>
<languageid="F">
<name>Nom</name>
<number>Numméro</number>
<street>Rue</street>
<country>Pays</country>
</language>
</main>


Different languages are separated by the <language
id="languageid" /> tags. The languageid attribute should
be passed to the constructor of the class.


Using the class
Using the object is pretty straightforward. You create a
new instance of the object in the OnInit(.) member
function of your page object. Suppose we have a page
called client.aspx containing client data. The name of the
codebehind file is client.aspx.cs. To make things simple,
we name the xml file client.xml.

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);

XmlLang Lang = new XmlLang("client.xml",Session
["LANGUAGE"].ToString());

this.NameLabel.Text = Lang.GetString("name");

this.StreetLabel.Text = Lang.GetString("street");

this.CountryLabel.Text = Lang.GetString("country");
}



Instead of hard-coding all static text in client.aspx, we
use labels as a replacement. In the OnInit member
function, these labels are filled with the right contents,
depending on the selected language. In this example, the
chosen language is stored in a session variable : Session
["LANGUAGE"]. The method as it is mentioned also allows
you to change column headers from a datagrid object.
**********************************************************
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top