Webparts and FindControl

Discussion in 'ASP .Net' started by Josh Valino, Apr 2, 2008.

  1. Josh Valino

    Josh Valino Guest

    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
     
    Josh Valino, Apr 2, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    0
    Views:
    3,820
  2. ALI-R

    ASP.Net Framework2 and webparts

    ALI-R, Mar 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    390
    Brock Allen
    Mar 16, 2005
  3. =?Utf-8?B?QXN0ZXJh?=

    Webparts and ViewState

    =?Utf-8?B?QXN0ZXJh?=, Jun 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    487
    =?Utf-8?B?QXN0ZXJh?=
    Jun 7, 2005
  4. =?Utf-8?B?U2hlbGw=?=

    How to give 3d Look to Datagrid and WebParts control?

    =?Utf-8?B?U2hlbGw=?=, Oct 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    564
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Oct 28, 2005
  5. =?Utf-8?B?SmF2?=

    Do MasterPages and WebParts not mix!

    =?Utf-8?B?SmF2?=, Jun 12, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    345
    =?Utf-8?B?SmF2?=
    Jun 12, 2006
Loading...

Share This Page