Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding control on a page
Message
De
10/11/2010 16:41:18
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
10/11/2010 16:15:27
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01488738
Message ID:
01488756
Vues:
37
>>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.....


Like so:

http://pastie.org/1288254
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform