System.Web.UI.Control

  • Thread starter Thread starter Tascien
  • Start date Start date
T

Tascien

Guys,

I am trying to run through the page controls, if the controls' id is
found in the database, then I change the corresponding text from the
database. but, the system is coming back with error:

BC30456: 'Text' is not a member of 'System.Web.UI.Control'.

how. I am sure the label control has a text property.

here is my function:

function showControls()
Dim c as control
for each c in page.controls
response.Write(c.ID & "<BR>") <-- this works...
c.Text = "I have been changed" <-- this fails ! why?
testme.Text = "I have been changed"
next
End Function




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<script language="VB" runat="server">
Sub Page_Load(Sender as Object, e as EventArgs)
showControls()
End sub
function showControls()
Dim c as control
for each c in page.controls
response.Write(c.ID & "<BR>")
c.Text = "I have been changed"
testme.Text = "I have been changed"
next
End Function
</script>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body>
<asp:label ID="testme" Text="I am here" runat="server"/>
</body>
</html>
 
The System.Web.UI.Control class doesn't have a text property. Classes like
the Label inherit from this and extend it. In order to set the text property
of c you would have to make a cast to the type Label.

You can try something like

if(c.GetType() == "System.Web.UI.WebControls.Label")
{
c.Text = "I have changed";
}


Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Mark Fitzpatrick said:
The System.Web.UI.Control class doesn't have a text property. Classes like
the Label inherit from this and extend it. In order to set the text property
of c you would have to make a cast to the type Label.

You can try something like

if(c.GetType() == "System.Web.UI.WebControls.Label")
{
c.Text = "I have changed";
}

How about casting to Label first:

((System.Web.UI.WebControls.Label) c).Text = "I have changed";
 
Back
Top