Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding control on a page
Message
From
10/11/2010 16:15:27
 
 
To
10/11/2010 13:53:41
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01488738
Message ID:
01488754
Views:
34
>I am frequently adding controls manually on a page. When this is the case, this is because everything is based on the database and this serves for a very special purpose. However, I was wondering when we add controls manually on the page such as:
>
>
>        ' Find the control to hold the customized page
>        loControl = Page.FindControl("LabelDataEntry")
>
>                ' Add the table definition
>                loControlLiteral = New System.Web.UI.WebControls.Literal
>                loControlLiteral.Text = loControlLiteral.Text + "<TR>"
>                loControlLiteral.Text = loControlLiteral.Text + "<TD ALIGN=RIGHT>" + lcLabel + ":"
>                loControlLiteral.Text = loControlLiteral.Text + "<TD> "
>                loControlLiteral.Text = loControlLiteral.Text + "<TD>"
>                loControlLiteral.ID = "MyNewID"
>                loControl.Controls.Add(loControlLiteral)
>
>
>...would there be a way to have the FindControl() method to recognize this newly added control as if it was originally part of the .aspx page?
>
>For example, the FindControl() line in this code finds the control on the page because it is natively part of the .aspx. But, the "MyNewID" is added manually. On that page, if I would do a FindControl() on that one after it has been added, it won't find it.
>
>I was wondering if there could be a method somewhere or something that would make the control live.

I thought .FindControl() only finds a control that is the immediate 'child' of the object? So in the above example 'Page.FindControl("LabelDataEntry").FindControl("MyNewId") would probably work - but you could write a recursive version of FindControl that would be more flexible.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform