|
 |
aspx thread: UserControl Error
Message #1 by "Dean Santillan" <webmaster@5...> on Fri, 10 May 2002 07:13:25
|
|
I keep on getting this error below, and I have no idea how to
resolve the issue i have tried changing and playing with it but am
not getting anywhere.
Could someone put me in the right direction. When done for the
System.Web.UI.Page
there are nbo errors as Soon as I change it to System.Web.UI.UserControl
it gives me tbhe following error.
E:\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
expected.
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 poibnters as to what I could do.
Thanks
Dean
Message #2 by "Dean Santillan" <webmaster@5...> on Fri, 10 May 2002 17:06:46
|
|
Noone seems to want to answer tbhis question. Is this not a valid question?
> I keep on getting this error below, and I have no idea how to
r> esolve the issue i have tried changing and playing with it but am
n> ot getting anywhere.
> Could someone put me in the right direction. When done for the
S> ystem.Web.UI.Page
t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
i> t gives me tbhe following error.
>
E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
e> xpected.
> Translator.TranslateControl(UserControl, "New", lang);
> Here is the class file that has the translate method
p> ublic static void TranslateControl(System.Web.UI.UserControl
t> argetControl,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
d> ocument
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform with the name of the
c> urrent 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
p> ageName,
s> tring lang)
> {
> XmlDocument doc = new XmlDocument();
> // loads the xml file
> doc.Load(targetPage.MapPath(pageName + ".xml"));
> // loops through all nodes in the <webpage> root
n> ode of the xml document
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform
w> ith the name of the current
n> ode
> Control c = targetPage.FindControl(anode.Name);
> if (c != null)
> {
> switch ( c.GetType().ToString() )
> {
>
> case "System.Web.UI.WebControls.Label":
> /* if the
w> ebcontrol found is a Label control,
> * set its Text
p> roperty to the inner text of
> * the children
n> ode */
> Label lb = (Label) c;
> lb.Text = anode[lang].InnerText;
> break;
> case "System.Web.UI.WebControls.LinkButton":
> /* same for a
L> inkButton control, and for other
> * smarts controls
l> ike 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
c> omplex control like DropDownList
> * or ListBox, we
l> oops inside each <item> node
> * and creates a
n> ew ListItem in the control */
> DropDownList ddl = (DropDownList) c;
> // loops through
e> ach <item> node
> foreach (XmlNode itemNode in
anode.ChildNodes)
> {
> ListItem
l> i = new ListItem();
> li.Text = itemNode["text"]
[lang].InnerText;
> li.Value = itemNode["value"].InnerText;
>
> ddl.Items.Add(li);
> }
> break;
> }
> }
> }
> }
> }
> Any poibnters as to what I could do.
> Thanks
D> ean
Message #3 by Feduke Cntr Charles R <FedukeCR@m...> on Fri, 10 May 2002 12:07:17 -0400
|
|
Dean,
> Noone seems to want to answer tbhis question. Is this not a valid
question?
Post your codebehind file from the top of the file to the
declaration of the class, and I'll see if I can help.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:07 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Noone seems to want to answer tbhis question. Is this not a valid question?
> I keep on getting this error below, and I have no idea how to
r> esolve the issue i have tried changing and playing with it but am
n> ot getting anywhere.
> Could someone put me in the right direction. When done for the
S> ystem.Web.UI.Page
t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
i> t gives me tbhe following error.
>
E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
e> xpected.
> Translator.TranslateControl(UserControl, "New", lang);
> Here is the class file that has the translate method
p> ublic static void TranslateControl(System.Web.UI.UserControl
t> argetControl,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
d> ocument
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform with the name of the
c> urrent 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
p> ageName,
s> tring lang)
> {
> XmlDocument doc = new XmlDocument();
> // loads the xml file
> doc.Load(targetPage.MapPath(pageName + ".xml"));
> // loops through all nodes in the <webpage> root
n> ode of the xml document
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform
w> ith the name of the current
n> ode
> Control c = targetPage.FindControl(anode.Name);
> if (c != null)
> {
> switch ( c.GetType().ToString() )
> {
>
> case "System.Web.UI.WebControls.Label":
> /* if the
w> ebcontrol found is a Label control,
> * set its Text
p> roperty to the inner text of
> * the children
n> ode */
> Label lb = (Label) c;
> lb.Text = anode[lang].InnerText;
> break;
> case "System.Web.UI.WebControls.LinkButton":
> /* same for a
L> inkButton control, and for other
> * smarts controls
l> ike 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
c> omplex control like DropDownList
> * or ListBox, we
l> oops inside each <item> node
> * and creates a
n> ew ListItem in the control */
> DropDownList ddl = (DropDownList) c;
> // loops through
e> ach <item> node
> foreach (XmlNode itemNode in
anode.ChildNodes)
> {
> ListItem
l> i = new ListItem();
> li.Text = itemNode["text"]
[lang].InnerText;
> li.Value = itemNode["value"].InnerText;
>
> ddl.Items.Add(li);
> }
> break;
> }
> }
> }
> }
> }
> Any poibnters as to what I could do.
> Thanks
D> ean
Message #4 by "Dean Santillan" <webmaster@5...> on Sat, 11 May 2002 02:32:05 +0900
|
|
Thanks Chuck,
This the code for the webform code behind
the one after is for the usercontrol
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class intl : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
public intl()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
string lang = "";
/* is the language code is in a session-state variable */
if (Session["lang"] != null) {
lang = Session["lang"].ToString();
} else {
/* the language code should be taken from the URL (querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default language if no
'lang' params has been passed to the page
Translator.Translate(Page, "intl", lang);
}
protected void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
}
USERCONTROL CODEBEHIND
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Evolusys.Careers.DataLayer;
using Evolusys.Careers.SiteConfiguration;
/// <summary>
/// Summary description for New.
/// </summary>
public abstract class New : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label ControlTitle;
protected System.Web.UI.WebControls.Label InstructionText;
protected System.Web.UI.WebControls.Label FormTitle;
protected System.Web.UI.WebControls.Label FirstName;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label LastName;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Email;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label Password;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label ConfirmPassword;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.Label ReferredBy;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Button RegisterButton;
/// <summary>
public New()
{
this.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
string lang = "";
/* is the language code is in a session-state variable */
if (Session["lang"] != null)
{
lang = Session["lang"].ToString();
}
else
{
/* the language code should be taken from the URL (querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default language if no 'lang'
params has been passed to the page
Translator.Translate(Page, "New", lang);
}
private void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Saturday, May 11, 2002 1:07 AM
To: ASP+
Subject: [aspx] Re: UserControl Error
Dean,
> Noone seems to want to answer tbhis question. Is this not a valid
question?
Post your codebehind file from the top of the file to the
declaration of the class, and I'll see if I can help.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:07 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Noone seems to want to answer tbhis question. Is this not a valid question?
> I keep on getting this error below, and I have no idea how to
r> esolve the issue i have tried changing and playing with it but am
n> ot getting anywhere.
> Could someone put me in the right direction. When done for the
S> ystem.Web.UI.Page
t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
i> t gives me tbhe following error.
>
E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
e> xpected.
> Translator.TranslateControl(UserControl, "New", lang);
> Here is the class file that has the translate method
p> ublic static void TranslateControl(System.Web.UI.UserControl
t> argetControl,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
d> ocument
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform with the name of the
c> urrent 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
p> ageName,
s> tring lang)
> {
> XmlDocument doc = new XmlDocument();
> // loads the xml file
> doc.Load(targetPage.MapPath(pageName + ".xml"));
> // loops through all nodes in the <webpage> root
n> ode of the xml document
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform
w> ith the name of the current
n> ode
> Control c = targetPage.FindControl(anode.Name);
> if (c != null)
> {
> switch ( c.GetType().ToString() )
> {
>
> case "System.Web.UI.WebControls.Label":
> /* if the
w> ebcontrol found is a Label control,
> * set its Text
p> roperty to the inner text of
> * the children
n> ode */
> Label lb = (Label) c;
> lb.Text = anode[lang].InnerText;
> break;
> case "System.Web.UI.WebControls.LinkButton":
> /* same for a
L> inkButton control, and for other
> * smarts controls
l> ike 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
c> omplex control like DropDownList
> * or ListBox, we
l> oops inside each <item> node
> * and creates a
n> ew ListItem in the control */
> DropDownList ddl = (DropDownList) c;
> // loops through
e> ach <item> node
> foreach (XmlNode itemNode in
anode.ChildNodes)
> {
> ListItem
l> i = new ListItem();
> li.Text = itemNode["text"]
[lang].InnerText;
> li.Value = itemNode["value"].InnerText;
>
> ddl.Items.Add(li);
> }
> break;
> }
> }
> }
> }
> }
> Any poibnters as to what I could do.
> Thanks
D> ean
Message #5 by Feduke Cntr Charles R <FedukeCR@m...> on Fri, 10 May 2002 13:21:27 -0400
|
|
Dean,
The only thing I can see is the class has the keyword "abstract".
This is the same as "MustInherit" in VB, and by default this is what VS.NET
IDE/C# will put in your *.cs. Try removing "abstract"; although I have
never encountered this, I religiously remove "abstract" whenever I create a
UserControl or class that is not abstract (of course a page really needs to
inherit the class in the first place, so abstract is [usually] perfectly
fine here).
How are you trying to get the page to display? If you're going
directly to the *.ascx file then I'd imagine you'd be getting some kind of
error. You need to put the UserControl in a Page, if you haven't done so
already.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:32 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Thanks Chuck,
This the code for the webform code behind
the one after is for the usercontrol
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class intl : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.DropDownList
DropDownList1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
public intl()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
string lang = "";
/* is the language code is in a session-state variable */
if (Session["lang"] != null) {
lang = Session["lang"].ToString();
} else {
/* the language code should be taken from the URL
(querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default language if
no
'lang' params has been passed to the page
Translator.Translate(Page, "intl", lang);
}
protected void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
}
}
USERCONTROL CODEBEHIND
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Evolusys.Careers.DataLayer;
using Evolusys.Careers.SiteConfiguration;
/// <summary>
/// Summary description for New.
/// </summary>
public abstract class New : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label ControlTitle;
protected System.Web.UI.WebControls.Label InstructionText;
protected System.Web.UI.WebControls.Label FormTitle;
protected System.Web.UI.WebControls.Label FirstName;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label LastName;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Email;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label Password;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label ConfirmPassword;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.Label ReferredBy;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Button RegisterButton;
/// <summary>
public New()
{
this.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
string lang = "";
/* is the language code is in a session-state
variable */
if (Session["lang"] != null)
{
lang = Session["lang"].ToString();
}
else
{
/* the language code should be taken from
the URL (querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default
language if no 'lang'
params has been passed to the page
Translator.Translate(Page, "New", lang);
}
private void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// Required method for Designer support - do
not modify
/// the contents of this method with the code
editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
}
}
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Saturday, May 11, 2002 1:07 AM
To: ASP+
Subject: [aspx] Re: UserControl Error
Dean,
> Noone seems to want to answer tbhis question. Is this not a valid
question?
Post your codebehind file from the top of the file to the
declaration of the class, and I'll see if I can help.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:07 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Noone seems to want to answer tbhis question. Is this not a valid question?
> I keep on getting this error below, and I have no idea how to
r> esolve the issue i have tried changing and playing with it but am
n> ot getting anywhere.
> Could someone put me in the right direction. When done for the
S> ystem.Web.UI.Page
t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
i> t gives me tbhe following error.
>
E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
e> xpected.
> Translator.TranslateControl(UserControl, "New", lang);
> Here is the class file that has the translate method
p> ublic static void TranslateControl(System.Web.UI.UserControl
t> argetControl,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
d> ocument
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform with the name of the
c> urrent 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
p> ageName,
s> tring lang)
> {
> XmlDocument doc = new XmlDocument();
> // loads the xml file
> doc.Load(targetPage.MapPath(pageName + ".xml"));
> // loops through all nodes in the <webpage> root
n> ode of the xml document
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform
w> ith the name of the current
n> ode
> Control c = targetPage.FindControl(anode.Name);
> if (c != null)
> {
> switch ( c.GetType().ToString() )
> {
>
> case "System.Web.UI.WebControls.Label":
> /* if the
w> ebcontrol found is a Label control,
> * set its Text
p> roperty to the inner text of
> * the children
n> ode */
> Label lb = (Label) c;
> lb.Text = anode[lang].InnerText;
> break;
> case "System.Web.UI.WebControls.LinkButton":
> /* same for a
L> inkButton control, and for other
> * smarts controls
l> ike 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
c> omplex control like DropDownList
> * or ListBox, we
l> oops inside each <item> node
> * and creates a
n> ew ListItem in the control */
> DropDownList ddl = (DropDownList) c;
> // loops through
e> ach <item> node
> foreach (XmlNode itemNode in
anode.ChildNodes)
> {
> ListItem
l> i = new ListItem();
> li.Text = itemNode["text"]
[lang].InnerText;
> li.Value = itemNode["value"].InnerText;
>
> ddl.Items.Add(li);
> }
> break;
> }
> }
> }
> }
> }
> Any poibnters as to what I could do.
> Thanks
D> ean
Message #6 by "Dean Santillan" <webmaster@5...> on Sat, 11 May 2002 10:08:39 +0900
|
|
Chuck,
The usercontrol is embedded in the page. When I use the Page object I get no
errors
but the usercontrol webcontrols are not filled at all they are left empty.
But when i use the usercontrol I get the error. I removed the abstract
keyword to no avail.
How can i access the the webcontrols in the usercontrol from the page?
Dean
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Saturday, May 11, 2002 2:21 AM
To: ASP+
Subject: [aspx] Re: UserControl Error
Dean,
The only thing I can see is the class has the keyword "abstract".
This is the same as "MustInherit" in VB, and by default this is what VS.NET
IDE/C# will put in your *.cs. Try removing "abstract"; although I have
never encountered this, I religiously remove "abstract" whenever I create a
UserControl or class that is not abstract (of course a page really needs to
inherit the class in the first place, so abstract is [usually] perfectly
fine here).
How are you trying to get the page to display? If you're going
directly to the *.ascx file then I'd imagine you'd be getting some kind of
error. You need to put the UserControl in a Page, if you haven't done so
already.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:32 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Thanks Chuck,
This the code for the webform code behind
the one after is for the usercontrol
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class intl : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.DropDownList
DropDownList1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
public intl()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
string lang = "";
/* is the language code is in a session-state variable */
if (Session["lang"] != null) {
lang = Session["lang"].ToString();
} else {
/* the language code should be taken from the URL
(querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default language if
no
'lang' params has been passed to the page
Translator.Translate(Page, "intl", lang);
}
protected void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
}
}
USERCONTROL CODEBEHIND
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Evolusys.Careers.DataLayer;
using Evolusys.Careers.SiteConfiguration;
/// <summary>
/// Summary description for New.
/// </summary>
public abstract class New : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label ControlTitle;
protected System.Web.UI.WebControls.Label InstructionText;
protected System.Web.UI.WebControls.Label FormTitle;
protected System.Web.UI.WebControls.Label FirstName;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label LastName;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Email;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label Password;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label ConfirmPassword;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.Label ReferredBy;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Button RegisterButton;
/// <summary>
public New()
{
this.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
string lang = "";
/* is the language code is in a session-state
variable */
if (Session["lang"] != null)
{
lang = Session["lang"].ToString();
}
else
{
/* the language code should be taken from
the URL (querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default
language if no 'lang'
params has been passed to the page
Translator.Translate(Page, "New", lang);
}
private void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// Required method for Designer support - do
not modify
/// the contents of this method with the code
editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
}
}
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Saturday, May 11, 2002 1:07 AM
To: ASP+
Subject: [aspx] Re: UserControl Error
Dean,
> Noone seems to want to answer tbhis question. Is this not a valid
question?
Post your codebehind file from the top of the file to the
declaration of the class, and I'll see if I can help.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:07 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Noone seems to want to answer tbhis question. Is this not a valid question?
> I keep on getting this error below, and I have no idea how to
r> esolve the issue i have tried changing and playing with it but am
n> ot getting anywhere.
> Could someone put me in the right direction. When done for the
S> ystem.Web.UI.Page
t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
i> t gives me tbhe following error.
>
E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
e> xpected.
> Translator.TranslateControl(UserControl, "New", lang);
> Here is the class file that has the translate method
p> ublic static void TranslateControl(System.Web.UI.UserControl
t> argetControl,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
d> ocument
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform with the name of the
c> urrent 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
p> ageName,
s> tring lang)
> {
> XmlDocument doc = new XmlDocument();
> // loads the xml file
> doc.Load(targetPage.MapPath(pageName + ".xml"));
> // loops through all nodes in the <webpage> root
n> ode of the xml document
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform
w> ith the name of the current
n> ode
> Control c = targetPage.FindControl(anode.Name);
> if (c != null)
> {
> switch ( c.GetType().ToString() )
> {
>
> case "System.Web.UI.WebControls.Label":
> /* if the
w> ebcontrol found is a Label control,
> * set its Text
p> roperty to the inner text of
> * the children
n> ode */
> Label lb = (Label) c;
> lb.Text = anode[lang].InnerText;
> break;
> case "System.Web.UI.WebControls.LinkButton":
> /* same for a
L> inkButton control, and for other
> * smarts controls
l> ike 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
c> omplex control like DropDownList
> * or ListBox, we
l> oops inside each <item> node
> * and creates a
n> ew ListItem in the control */
> DropDownList ddl = (DropDownList) c;
> // loops through
e> ach <item> node
> foreach (XmlNode itemNode in
anode.ChildNodes)
> {
> ListItem
l> i = new ListItem();
> li.Text = itemNode["text"]
[lang].InnerText;
> li.Value = itemNode["value"].InnerText;
>
> ddl.Items.Add(li);
> }
> break;
> }
> }
> }
> }
> }
> Any poibnters as to what I could do.
> Thanks
D> ean
Message #7 by "Dean Santillan" <webmaster@5...> on Sat, 11 May 2002 11:20:59 +0900
|
|
I have corrected the problem, the usercontrol wont work so i used the pabge
object
and did this to access the webcontrols of the usercontrol
Page.Findcontrol(UserControl).FindControl(XMLNODE);
It works fine, but you think it would work fine by itself.
Sometbhing i habvent tried for 4 days tbhen it clicks to me to do this.
Thanks for the help
Dean
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Saturday, May 11, 2002 10:09 AM
To: ASP+
Subject: [aspx] Re: UserControl Error
Chuck,
The usercontrol is embedded in the page. When I use the Page object I get no
errors
but the usercontrol webcontrols are not filled at all they are left empty.
But when i use the usercontrol I get the error. I removed the abstract
keyword to no avail.
How can i access the the webcontrols in the usercontrol from the page?
Dean
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Saturday, May 11, 2002 2:21 AM
To: ASP+
Subject: [aspx] Re: UserControl Error
Dean,
The only thing I can see is the class has the keyword "abstract".
This is the same as "MustInherit" in VB, and by default this is what VS.NET
IDE/C# will put in your *.cs. Try removing "abstract"; although I have
never encountered this, I religiously remove "abstract" whenever I create a
UserControl or class that is not abstract (of course a page really needs to
inherit the class in the first place, so abstract is [usually] perfectly
fine here).
How are you trying to get the page to display? If you're going
directly to the *.ascx file then I'd imagine you'd be getting some kind of
error. You need to put the UserControl in a Page, if you haven't done so
already.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:32 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Thanks Chuck,
This the code for the webform code behind
the one after is for the usercontrol
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class intl : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.DropDownList
DropDownList1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
public intl()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
string lang = "";
/* is the language code is in a session-state variable */
if (Session["lang"] != null) {
lang = Session["lang"].ToString();
} else {
/* the language code should be taken from the URL
(querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default language if
no
'lang' params has been passed to the page
Translator.Translate(Page, "intl", lang);
}
protected void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
}
}
USERCONTROL CODEBEHIND
namespace DevWeb.XmlIntl
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Evolusys.Careers.DataLayer;
using Evolusys.Careers.SiteConfiguration;
/// <summary>
/// Summary description for New.
/// </summary>
public abstract class New : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label ControlTitle;
protected System.Web.UI.WebControls.Label InstructionText;
protected System.Web.UI.WebControls.Label FormTitle;
protected System.Web.UI.WebControls.Label FirstName;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label LastName;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Email;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label Password;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label ConfirmPassword;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.Label ReferredBy;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Button RegisterButton;
/// <summary>
public New()
{
this.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
string lang = "";
/* is the language code is in a session-state
variable */
if (Session["lang"] != null)
{
lang = Session["lang"].ToString();
}
else
{
/* the language code should be taken from
the URL (querystring) */
lang = Request["lang"];
}
if (lang == "") lang = "en"; // sets a default
language if no 'lang'
params has been passed to the page
Translator.Translate(Page, "New", lang);
}
private void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// Required method for Designer support - do
not modify
/// the contents of this method with the code
editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
}
}
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Saturday, May 11, 2002 1:07 AM
To: ASP+
Subject: [aspx] Re: UserControl Error
Dean,
> Noone seems to want to answer tbhis question. Is this not a valid
question?
Post your codebehind file from the top of the file to the
declaration of the class, and I'll see if I can help.
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Friday, May 10, 2002 1:07 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
Noone seems to want to answer tbhis question. Is this not a valid question?
> I keep on getting this error below, and I have no idea how to
r> esolve the issue i have tried changing and playing with it but am
n> ot getting anywhere.
> Could someone put me in the right direction. When done for the
S> ystem.Web.UI.Page
t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
i> t gives me tbhe following error.
>
E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
e> xpected.
> Translator.TranslateControl(UserControl, "New", lang);
> Here is the class file that has the translate method
p> ublic static void TranslateControl(System.Web.UI.UserControl
t> argetControl,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
d> ocument
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform with the name of the
c> urrent 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
p> ageName,
s> tring lang)
> {
> XmlDocument doc = new XmlDocument();
> // loads the xml file
> doc.Load(targetPage.MapPath(pageName + ".xml"));
> // loops through all nodes in the <webpage> root
n> ode of the xml document
> foreach (XmlNode anode in doc["webpage"].ChildNodes)
> {
> // looks for a webcontrol in the webform
w> ith the name of the current
n> ode
> Control c = targetPage.FindControl(anode.Name);
> if (c != null)
> {
> switch ( c.GetType().ToString() )
> {
>
> case "System.Web.UI.WebControls.Label":
> /* if the
w> ebcontrol found is a Label control,
> * set its Text
p> roperty to the inner text of
> * the children
n> ode */
> Label lb = (Label) c;
> lb.Text = anode[lang].InnerText;
> break;
> case "System.Web.UI.WebControls.LinkButton":
> /* same for a
L> inkButton control, and for other
> * smarts controls
l> ike 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
c> omplex control like DropDownList
> * or ListBox, we
l> oops inside each <item> node
> * and creates a
n> ew ListItem in the control */
> DropDownList ddl = (DropDownList) c;
> // loops through
e> ach <item> node
> foreach (XmlNode itemNode in
anode.ChildNodes)
> {
> ListItem
l> i = new ListItem();
> li.Text = itemNode["text"]
[lang].InnerText;
> li.Value = itemNode["value"].InnerText;
>
> ddl.Items.Add(li);
> }
> break;
> }
> }
> }
> }
> }
> Any poibnters as to what I could do.
> Thanks
D> ean
Message #8 by Imar Spaanjaars <Imar@S...> on Sat, 11 May 2002 07:11:48 +0200
|
|
It looks like you haven't declared your user control in the code behind
page of your aspx page.
Add something like:
protected MyUserControlClass MyUserControl1;
This will enable you to reference the User Control.
HtH
Imar
At 11:20 AM 5/11/2002 +0900, you wrote:
>I have corrected the problem, the usercontrol wont work so i used the pabge
>object
>and did this to access the webcontrols of the usercontrol
>
>Page.Findcontrol(UserControl).FindControl(XMLNODE);
>
>It works fine, but you think it would work fine by itself.
>Sometbhing i habvent tried for 4 days tbhen it clicks to me to do this.
>
>Thanks for the help
>Dean
>
>-----Original Message-----
>From: Dean Santillan [mailto:webmaster@5...]
>Sent: Saturday, May 11, 2002 10:09 AM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Chuck,
>
>The usercontrol is embedded in the page. When I use the Page object I get no
>errors
>but the usercontrol webcontrols are not filled at all they are left empty.
>But when i use the usercontrol I get the error. I removed the abstract
>keyword to no avail.
>
>How can i access the the webcontrols in the usercontrol from the page?
>
>Dean
>
>-----Original Message-----
>From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
>Sent: Saturday, May 11, 2002 2:21 AM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Dean,
>
> The only thing I can see is the class has the keyword "abstract".
>This is the same as "MustInherit" in VB, and by default this is what VS.NET
>IDE/C# will put in your *.cs. Try removing "abstract"; although I have
>never encountered this, I religiously remove "abstract" whenever I create a
>UserControl or class that is not abstract (of course a page really needs to
>inherit the class in the first place, so abstract is [usually] perfectly
>fine here).
>
> How are you trying to get the page to display? If you're going
>directly to the *.ascx file then I'd imagine you'd be getting some kind of
>error. You need to put the UserControl in a Page, if you haven't done so
>already.
>
>- Chuck
>
>-----Original Message-----
>From: Dean Santillan [mailto:webmaster@5...]
>Sent: Friday, May 10, 2002 1:32 PM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Thanks Chuck,
>
>This the code for the webform code behind
>the one after is for the usercontrol
>
>namespace DevWeb.XmlIntl
>{
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
>
>
> public class intl : System.Web.UI.Page
> {
> protected System.Web.UI.WebControls.Label Label1;
> protected System.Web.UI.WebControls.Label Label2;
> protected System.Web.UI.WebControls.LinkButton LinkButton1;
> protected System.Web.UI.WebControls.DropDownList
>DropDownList1;
> protected System.Web.UI.WebControls.HyperLink HyperLink1;
>
> public intl()
> {
> Page.Init += new System.EventHandler(Page_Init);
> }
>
> protected void Page_Load(object sender, EventArgs e)
> {
> string lang = "";
>
> /* is the language code is in a session-state variable */
> if (Session["lang"] != null) {
> lang = Session["lang"].ToString();
> } else {
> /* the language code should be taken from the URL
>(querystring) */
> lang = Request["lang"];
> }
>
> if (lang == "") lang = "en"; // sets a default language if
>no
>'lang' params has been passed to the page
>
> Translator.Translate(Page, "intl", lang);
>
> }
>
> protected void Page_Init(object sender, EventArgs e)
> {
> InitializeComponent();
> }
>
> private void InitializeComponent()
> {
> this.Load += new
>System.EventHandler(this.Page_Load);
>
> }
> }
>}
>
>USERCONTROL CODEBEHIND
>namespace DevWeb.XmlIntl
>{
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Xml;
> using Evolusys.Careers.DataLayer;
> using Evolusys.Careers.SiteConfiguration;
>
> /// <summary>
> /// Summary description for New.
> /// </summary>
> public abstract class New : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.Label ControlTitle;
> protected System.Web.UI.WebControls.Label InstructionText;
> protected System.Web.UI.WebControls.Label FormTitle;
> protected System.Web.UI.WebControls.Label FirstName;
> protected System.Web.UI.WebControls.TextBox TextBox1;
> protected System.Web.UI.WebControls.Label LastName;
> protected System.Web.UI.WebControls.TextBox TextBox2;
> protected System.Web.UI.WebControls.Label Email;
> protected System.Web.UI.WebControls.TextBox TextBox3;
> protected System.Web.UI.WebControls.Label Password;
> protected System.Web.UI.WebControls.TextBox TextBox4;
> protected System.Web.UI.WebControls.Label ConfirmPassword;
> protected System.Web.UI.WebControls.TextBox TextBox5;
> protected System.Web.UI.WebControls.Label ReferredBy;
> protected System.Web.UI.WebControls.TextBox TextBox6;
> protected System.Web.UI.WebControls.Button RegisterButton;
>
>
> /// <summary>
> public New()
> {
> this.Init += new System.EventHandler(Page_Init);
> }
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> string lang = "";
>
> /* is the language code is in a session-state
>variable */
> if (Session["lang"] != null)
> {
> lang = Session["lang"].ToString();
> }
> else
> {
> /* the language code should be taken from
>the URL (querystring) */
> lang = Request["lang"];
> }
>
> if (lang == "") lang = "en"; // sets a default
>language if no 'lang'
>params has been passed to the page
>
> Translator.Translate(Page, "New", lang);
> }
>
> private void Page_Init(object sender, EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web
>Form Designer.
> //
> InitializeComponent();
> }
>
> #region Web Form Designer generated code
> /// Required method for Designer support - do
>not modify
> /// the contents of this method with the code
>editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Load += new
>System.EventHandler(this.Page_Load);
>
> }
> #endregion
> }
>}
>
>-----Original Message-----
>From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
>Sent: Saturday, May 11, 2002 1:07 AM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Dean,
>
> > Noone seems to want to answer tbhis question. Is this not a valid
>question?
>
> Post your codebehind file from the top of the file to the
>declaration of the class, and I'll see if I can help.
>
>- Chuck
>
>-----Original Message-----
>From: Dean Santillan [mailto:webmaster@5...]
>Sent: Friday, May 10, 2002 1:07 PM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Noone seems to want to answer tbhis question. Is this not a valid question?
>
>
> > I keep on getting this error below, and I have no idea how to
>r> esolve the issue i have tried changing and playing with it but am
>n> ot getting anywhere.
>
> > Could someone put me in the right direction. When done for the
>S> ystem.Web.UI.Page
>t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
>i> t gives me tbhe following error.
>
> >
>E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
>'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
>e> xpected.
>
> > Translator.TranslateControl(UserControl, "New", lang);
>
> > Here is the class file that has the translate method
>p> ublic static void TranslateControl(System.Web.UI.UserControl
>t> argetControl,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
>d> ocument
> > foreach (XmlNode anode in doc["webpage"].ChildNodes)
> > {
> > // looks for a webcontrol in the webform with the name of the
>c> urrent 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
>p> ageName,
>s> tring lang)
> > {
> > XmlDocument doc = new XmlDocument();
>
> > // loads the xml file
> > doc.Load(targetPage.MapPath(pageName + ".xml"));
>
> > // loops through all nodes in the <webpage> root
>n> ode of the xml document
> > foreach (XmlNode anode in doc["webpage"].ChildNodes)
> > {
> > // looks for a webcontrol in the webform
>w> ith the name of the current
>n> ode
> > Control c = targetPage.FindControl(anode.Name);
> > if (c != null)
> > {
> > switch ( c.GetType().ToString() )
> > {
> >
> > case "System.Web.UI.WebControls.Label":
> > /* if the
>w> ebcontrol found is a Label control,
> > * set its Text
>p> roperty to the inner text of
> > * the children
>n> ode */
> > Label lb = (Label) c;
> > lb.Text = anode[lang].InnerText;
> > break;
>
> > case "System.Web.UI.WebControls.LinkButton":
> > /* same for a
>L> inkButton control, and for other
> > * smarts controls
>l> ike 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
>c> omplex control like DropDownList
> > * or ListBox, we
>l> oops inside each <item> node
> > * and creates a
>n> ew ListItem in the control */
> > DropDownList ddl = (DropDownList) c;
>
> > // loops through
>e> ach <item> node
> > foreach (XmlNode itemNode in
>anode.ChildNodes)
> > {
> > ListItem
>l> i = new ListItem();
>
> > li.Text = itemNode["text"]
>[lang].InnerText;
> > li.Value = itemNode["value"].InnerText;
>
> >
> > ddl.Items.Add(li);
> > }
> > break;
> > }
> > }
> > }
> > }
> > }
>
> > Any poibnters as to what I could do.
>
> > Thanks
>D> ean
>
>
>
>
>
>
>
>
Message #9 by "Dean Santillan" <webmaster@5...> on Sat, 11 May 2002 15:23:04 +0900
|
|
But what if you are dynamically adding tbhe control to the webform from a
database call.
Then it wouldnt allow me the fumctionality of taking controls in and out of
the page. I would habve to go to every page and add it abnd thats not what i
want. I add usercontrols to the page depending on what the sectionID and
pageID is.
Thanks anyway
Dean
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Saturday, May 11, 2002 2:12 PM
To: ASP+
Subject: [aspx] Re: UserControl Error
It looks like you haven't declared your user control in the code behind
page of your aspx page.
Add something like:
protected MyUserControlClass MyUserControl1;
This will enable you to reference the User Control.
HtH
Imar
At 11:20 AM 5/11/2002 +0900, you wrote:
>I have corrected the problem, the usercontrol wont work so i used the pabge
>object
>and did this to access the webcontrols of the usercontrol
>
>Page.Findcontrol(UserControl).FindControl(XMLNODE);
>
>It works fine, but you think it would work fine by itself.
>Sometbhing i habvent tried for 4 days tbhen it clicks to me to do this.
>
>Thanks for the help
>Dean
>
>-----Original Message-----
>From: Dean Santillan [mailto:webmaster@5...]
>Sent: Saturday, May 11, 2002 10:09 AM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Chuck,
>
>The usercontrol is embedded in the page. When I use the Page object I get
no
>errors
>but the usercontrol webcontrols are not filled at all they are left empty.
>But when i use the usercontrol I get the error. I removed the abstract
>keyword to no avail.
>
>How can i access the the webcontrols in the usercontrol from the page?
>
>Dean
>
>-----Original Message-----
>From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
>Sent: Saturday, May 11, 2002 2:21 AM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Dean,
>
> The only thing I can see is the class has the keyword "abstract".
>This is the same as "MustInherit" in VB, and by default this is what VS.NET
>IDE/C# will put in your *.cs. Try removing "abstract"; although I have
>never encountered this, I religiously remove "abstract" whenever I create a
>UserControl or class that is not abstract (of course a page really needs to
>inherit the class in the first place, so abstract is [usually] perfectly
>fine here).
>
> How are you trying to get the page to display? If you're going
>directly to the *.ascx file then I'd imagine you'd be getting some kind of
>error. You need to put the UserControl in a Page, if you haven't done so
>already.
>
>- Chuck
>
>-----Original Message-----
>From: Dean Santillan [mailto:webmaster@5...]
>Sent: Friday, May 10, 2002 1:32 PM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Thanks Chuck,
>
>This the code for the webform code behind
>the one after is for the usercontrol
>
>namespace DevWeb.XmlIntl
>{
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
>
>
> public class intl : System.Web.UI.Page
> {
> protected System.Web.UI.WebControls.Label Label1;
> protected System.Web.UI.WebControls.Label Label2;
> protected System.Web.UI.WebControls.LinkButton
LinkButton1;
> protected System.Web.UI.WebControls.DropDownList
>DropDownList1;
> protected System.Web.UI.WebControls.HyperLink HyperLink1;
>
> public intl()
> {
> Page.Init += new System.EventHandler(Page_Init);
> }
>
> protected void Page_Load(object sender, EventArgs e)
> {
> string lang = "";
>
> /* is the language code is in a session-state variable */
> if (Session["lang"] != null) {
> lang = Session["lang"].ToString();
> } else {
> /* the language code should be taken from the URL
>(querystring) */
> lang = Request["lang"];
> }
>
> if (lang == "") lang = "en"; // sets a default language if
>no
>'lang' params has been passed to the page
>
> Translator.Translate(Page, "intl", lang);
>
> }
>
> protected void Page_Init(object sender, EventArgs e)
> {
> InitializeComponent();
> }
>
> private void InitializeComponent()
> {
> this.Load += new
>System.EventHandler(this.Page_Load);
>
> }
> }
>}
>
>USERCONTROL CODEBEHIND
>namespace DevWeb.XmlIntl
>{
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Xml;
> using Evolusys.Careers.DataLayer;
> using Evolusys.Careers.SiteConfiguration;
>
> /// <summary>
> /// Summary description for New.
> /// </summary>
> public abstract class New : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.Label ControlTitle;
> protected System.Web.UI.WebControls.Label InstructionText;
> protected System.Web.UI.WebControls.Label FormTitle;
> protected System.Web.UI.WebControls.Label FirstName;
> protected System.Web.UI.WebControls.TextBox TextBox1;
> protected System.Web.UI.WebControls.Label LastName;
> protected System.Web.UI.WebControls.TextBox TextBox2;
> protected System.Web.UI.WebControls.Label Email;
> protected System.Web.UI.WebControls.TextBox TextBox3;
> protected System.Web.UI.WebControls.Label Password;
> protected System.Web.UI.WebControls.TextBox TextBox4;
> protected System.Web.UI.WebControls.Label ConfirmPassword;
> protected System.Web.UI.WebControls.TextBox TextBox5;
> protected System.Web.UI.WebControls.Label ReferredBy;
> protected System.Web.UI.WebControls.TextBox TextBox6;
> protected System.Web.UI.WebControls.Button RegisterButton;
>
>
> /// <summary>
> public New()
> {
> this.Init += new System.EventHandler(Page_Init);
> }
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> string lang = "";
>
> /* is the language code is in a session-state
>variable */
> if (Session["lang"] != null)
> {
> lang = Session["lang"].ToString();
> }
> else
> {
> /* the language code should be taken from
>the URL (querystring) */
> lang = Request["lang"];
> }
>
> if (lang == "") lang = "en"; // sets a default
>language if no 'lang'
>params has been passed to the page
>
> Translator.Translate(Page, "New", lang);
> }
>
> private void Page_Init(object sender, EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET
Web
>Form Designer.
> //
> InitializeComponent();
> }
>
> #region Web Form Designer generated code
> /// Required method for Designer support - do
>not modify
> /// the contents of this method with the code
>editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Load += new
>System.EventHandler(this.Page_Load);
>
> }
> #endregion
> }
>}
>
>-----Original Message-----
>From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
>Sent: Saturday, May 11, 2002 1:07 AM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Dean,
>
> > Noone seems to want to answer tbhis question. Is this not a valid
>question?
>
> Post your codebehind file from the top of the file to the
>declaration of the class, and I'll see if I can help.
>
>- Chuck
>
>-----Original Message-----
>From: Dean Santillan [mailto:webmaster@5...]
>Sent: Friday, May 10, 2002 1:07 PM
>To: ASP+
>Subject: [aspx] Re: UserControl Error
>
>
>Noone seems to want to answer tbhis question. Is this not a valid question?
>
>
> > I keep on getting this error below, and I have no idea how to
>r> esolve the issue i have tried changing and playing with it but am
>n> ot getting anywhere.
>
> > Could someone put me in the right direction. When done for the
>S> ystem.Web.UI.Page
>t> here are nbo errors as Soon as I change it to System.Web.UI.UserControl
>i> t gives me tbhe following error.
>
> >
>E> :\DOTNETDEV\www.careers.jp\DevWeb\XmlIntl\New.ascx.cs(60):
>'> System.Web.UI.UserControl' denotes a 'class' where a 'variable' was
>e> xpected.
>
> > Translator.TranslateControl(UserControl, "New", lang);
>
> > Here is the class file that has the translate method
>p> ublic static void TranslateControl(System.Web.UI.UserControl
>t> argetControl,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
>d> ocument
> > foreach (XmlNode anode in doc["webpage"].ChildNodes)
> > {
> > // looks for a webcontrol in the webform with the name of the
>c> urrent 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
>p> ageName,
>s> tring lang)
> > {
> > XmlDocument doc = new XmlDocument();
>
> > // loads the xml file
> > doc.Load(targetPage.MapPath(pageName + ".xml"));
>
> > // loops through all nodes in the <webpage> root
>n> ode of the xml document
> > foreach (XmlNode anode in doc["webpage"].ChildNodes)
> > {
> > // looks for a webcontrol in the webform
>w> ith the name of the current
>n> ode
> > Control c = targetPage.FindControl(anode.Name);
> > if (c != null)
> > {
> > switch ( c.GetType().ToString() )
> > {
> >
> > case "System.Web.UI.WebControls.Label":
> > /* if the
>w> ebcontrol found is a Label control,
> > * set its Text
>p> roperty to the inner text of
> > * the children
>n> ode */
> > Label lb = (Label) c;
> > lb.Text = anode[lang].InnerText;
> > break;
>
> > case "System.Web.UI.WebControls.LinkButton":
> > /* same for a
>L> inkButton control, and for other
> > * smarts controls
>l> ike 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
>c> omplex control like DropDownList
> > * or ListBox, we
>l> oops inside each <item> node
> > * and creates a
>n> ew ListItem in the control */
> > DropDownList ddl = (DropDownList) c;
>
> > // loops through
>e> ach <item> node
> > foreach (XmlNode itemNode in
>anode.ChildNodes)
> > {
> > ListItem
>l> i = new ListItem();
>
> > li.Text = itemNode["text"]
>[lang].InnerText;
> > li.Value = itemNode["value"].InnerText;
>
> >
> > ddl.Items.Add(li);
> > }
> > break;
> > }
> > }
> > }
> > }
> > }
>
> > Any poibnters as to what I could do.
>
> > Thanks
>D> ean
>
>
>
>
>
>
>
>
|
|
 |