Webparts and FindControl

J

Josh Valino

Hi. I'm using asp.net 2.0 at my job and we have a site that uses webparts.
I'm curious if anyone can answer this. In the OnPreRender event of a
webpart, I have this:

foreach(Control x in this.Page.Controls)
{

}

As I step through this code, only one control is found, that is the master
page for the page that this web part sits in. The actual aspx page itself
has other controls, however. If I do this same loop in the actual
codebehind for the aspx, I get the expected results of seeing the other
controls that are in the page (labels, buttons, and what not)

What I'm trying to do is make it such that WebPart1 can get the clientID of
WebPart2, so that I can add some javascript in WebPart1 that will need to
reference WebPart2 by clientID. In WebPart1 I have a public property called
TargetControlID, and I set this property in the ASPX page that contains both
webparts. In the code for WebPart1, Page.FindControl(this.TargetControlID)
is unable to find that control by its ASP.Net ID.

Any thoughts?

TIA
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top