System.Web.UI.Control

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>
 
M

Mark Fitzpatrick

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
 
J

John Saunders

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";
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top