Page.Findcontrol in Class

Agrimiunigma

New Member
Heya, <BR><BR>I've got a class that needs to run a few methods on controls found on the page inheriting the class, but can't seem to access these controls. <BR><BR>Specifically, I have a placeholder on the page called "controlPH" that I need to add controls to within the class. I've tried something like this (extremely reduced version): <BR><BR>Public Class templateClass : Inherits Page <BR><BR>Public controlPH AS PlaceHolder <BR><BR>Public function getTemplateInfo() <BR>controlPH = Page.FindControl("controlPH") <BR>controlPH.Controls.Add(someControlHere) <BR>End function <BR><BR>End Class <BR><BR>This results in a "Object reference not set to an instance of an object." error. <BR><BR>I've already tried using new PlaceHolder, but that results in a new control and i need to add a controls to an existing place holder. <BR><BR>Any help definately appreciated, <BR><BR>])ryFor anyone interested I added another property to the class and passed the page from the calling .aspx file like so. <BR><BR>.ASPX: <BR><BR>Sub Page_Load(sender AS Object, e AS EventArgs) <BR><BR>dim templateInfo AS New templateClass() <BR>templateInfo.pageP = Page <BR>templateInfo.siteIDP = Request.Params("siteID") <BR>templateInfo.pageLvlMapP = Request.Params("pageLvlMap") <BR>templateInfo.aStateP = Request.Params("aState") <BR>templateInfo.getTemplateInfo() <BR><BR>End Sub <BR><BR>VB: <BR><BR>Public Property pageP AS page <BR>Get <BR>Return(currentPage) <BR>End get <BR>Set <BR>currentPage = value <BR>End Set <BR>End Property <BR><BR><BR>Public function getTemplateInfo() <BR><BR>controlPH = currentPage.FindControl("controlPH") <BR>controlPH.Controls.Add(someControlHere) <BR><BR>End function <BR><BR>])rytry something like this...<BR><BR>'************************************************* **<BR>Public controlPH As PlaceHolder<BR>Public function getTemplateInfo()<BR> Dim ctrlPlaceHolder As Control = Page.FindControl(controlPH)<BR> ctrlPlaceHolder.Controls.Add(Page.LoadControl(some ControlHere)<BR>End Function<BR>'************************************************* **<BR><BR>lemme know if that works,<BR>n1ckP
 
Back
Top