Hi,
I was reading an article on the www.asptoday.com site titled
"International Webforms Using XML". I downloaded the supportmaterial with
the article and installed it. It works fine. That is with the page object in
mind.
My question is how do I get it to work with a dynamically generated
usercontrol.
here is my the original and below is my code.
I ke ep onrecieving this error
E:\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
expected.
WEBFORM CODE BEHIND
Translator.Translate(Page, "intl", lang);
USERCONTROL CODE BEHIND
Translator.TranslateControl(UserControl, "New", lang);
Here is the class file that has the translate method
public static void TranslateControl(System.Web.UI.UserControl
targetControl,string ControlName, string lang)
{
XmlDocument doc = new XmlDocument();
// loads the xml file
doc.Load(targetControl.MapPath(ControlName + ".xml"));
// loops through all nodes in the <webpage> root node of the xml
document
foreach (XmlNode anode in doc["webpage"].ChildNodes)
{
// looks for a webcontrol in the webform with the name of the current node
Control c = targetControl.FindControl(anode.Name);
if (c != null)
{
switch ( c.GetType().ToString() )
{
case "System.Web.UI.WebControls.Label":
/* if the webcontrol found is a Label control,
* set its Text property to the inner text of
* the children node */
Label lb = (Label) c;
lb.Text = anode[lang].InnerText;
break;
case "System.Web.UI.WebControls.LinkButton":
/* same for a LinkButton control, and for other
* smarts controls like HyperLink or Button */
LinkButton lk = (LinkButton) c;
lk.Text = anode[lang].InnerText;
break;
case "System.Web.UI.WebControls.HyperLink":
HyperLink hl = (HyperLink) c;
hl.Text = anode[lang].InnerText;
break;
case "System.Web.UI.WebControls.DropDownList":
/* for more complex control like DropDownList
* or ListBox, we loops inside each <item> node
* and creates a new ListItem in the control */
DropDownList ddl = (DropDownList) c;
// loops through each <item> node
foreach (XmlNode itemNode in anode.ChildNodes)
{
ListItem li = new ListItem();
li.Text = itemNode["text"][lang].InnerText;
li.Value = itemNode["value"].InnerText;
ddl.Items.Add(li);
}
break;
}
}
}
}
public static void Translate(System.Web.UI.Page targetPage,string pageName,
string lang)
{
XmlDocument doc = new XmlDocument();
// loads the xml file
doc.Load(targetPage.MapPath(pageName + ".xml"));
// loops through all nodes in the <webpage> root node of the xml document
foreach (XmlNode anode in doc["webpage"].ChildNodes)
{
// looks for a webcontrol in the webform with the name of the current
node
Control c = targetPage.FindControl(anode.Name);
if (c != null)
{
switch ( c.GetType().ToString() )
{
case "System.Web.UI.WebControls.Label":
/* if the webcontrol found is a Label control,
* set its Text property to the inner text of
* the children node */
Label lb = (Label) c;
lb.Text = anode[lang].InnerText;
break;
case "System.Web.UI.WebControls.LinkButton":
/* same for a LinkButton control, and for other
* smarts controls like HyperLink or Button */
LinkButton lk = (LinkButton) c;
lk.Text = anode[lang].InnerText;
break;
case "System.Web.UI.WebControls.HyperLink":
HyperLink hl = (HyperLink) c;
hl.Text = anode[lang].InnerText;
break;
case "System.Web.UI.WebControls.DropDownList":
/* for more complex control like DropDownList
* or ListBox, we loops inside each <item> node
* and creates a new ListItem in the control */
DropDownList ddl = (DropDownList) c;
// loops through each <item> node
foreach (XmlNode itemNode in anode.ChildNodes)
{
ListItem li = new ListItem();
li.Text = itemNode["text"][lang].InnerText;
li.Value = itemNode["value"].InnerText;
ddl.Items.Add(li);
}
break;
}
}
}
}
}
Any help would be gradly appreciated
Thanks
Dean