.FindControl not seeing control

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

hey all,
i've added a dropdownlist object into tableCell td in my code
further down the code
i inspect the td.Controls
and i can see the the dropdownlist bright as day.
however, when i try to do
td.FindControl('id')
it returns null?

any ideas off the top why this may be?

thanks,
rodchar
 
hey all,
i've added a dropdownlist object into tableCell td in my code
further down the code
i inspect the td.Controls
and i can see the the dropdownlist bright as day.
however, when i try to do
td.FindControl('id')
it returns null?

any ideas off the top why this may be?

thanks,
rodchar

Take a look at the page's code and see if the control was renamed, it
might happens that the control is renamed if it's inside a grid (or
any list control for that matter). If so you need to search using the
ClientId
 
if i look at the page's code you're right it did get renamed because it's
coming from a user control, however take a look at the time of debugging,
just to show i'm not crazy here's the debug Immediate results:
?td.Controls[0]
{System.Web.UI.WebControls.DropDownList}
[System.Web.UI.WebControls.DropDownList]:
{System.Web.UI.WebControls.DropDownList}
AppRelativeTemplateSourceDirectory: "~/"
BindingContainer: null
ClientID: "drpJD_Job_Category"
Controls: {System.Web.UI.EmptyControlCollection}
EnableTheming: true
EnableViewState: true
ID: "drpJD_Job_Category"
NamingContainer: null
Page: null
Parent: {System.Web.UI.WebControls.TableCell}
Site: null
SkinID: ""
TemplateControl: null
TemplateSourceDirectory: "/hrrc"
UniqueID: "drpJD_Job_Category"
Visible: true
?td.FindControl("drpJD_Job_Category")
null
 
if i look at the page's code you're right it did get renamed because it's
coming from a user control, however take a look at the time of debugging,
just to show i'm not crazy here's the debug Immediate results:
?td.Controls[0]
{System.Web.UI.WebControls.DropDownList}
    [System.Web.UI.WebControls.DropDownList]:
{System.Web.UI.WebControls.DropDownList}
    AppRelativeTemplateSourceDirectory: "~/"
    BindingContainer: null
    ClientID: "drpJD_Job_Category"
    Controls: {System.Web.UI.EmptyControlCollection}
    EnableTheming: true
    EnableViewState: true
    ID: "drpJD_Job_Category"
    NamingContainer: null
    Page: null
    Parent: {System.Web.UI.WebControls.TableCell}
    Site: null
    SkinID: ""
    TemplateControl: null
    TemplateSourceDirectory: "/hrrc"
    UniqueID: "drpJD_Job_Category"
    Visible: true
?td.FindControl("drpJD_Job_Category")
null

:


Take a look at the page's code and see if the control was renamed, it
might happens that the control is renamed if it's inside a grid (or
any list control for that matter). If so you need to search using the
ClientId- Hide quoted text -

- Show quoted text -

Hi,

I fail to see what you want me to see.Sorry.

You know now the problem, the control is being renamed, either you
save the name of the control (by using ControlClientId) or you have to
search it by type, you could transverse the controls, looking for the
one you need.

Usually I keep the name of the controls I need using a
CommandArguments (I prefer to using OnCommand over OnClick)
 
well, as i showed in the debugging output above i'm doing a

?td.Controls[0]

and it finds the object i'm looking for, however, if i say

?td.FindControl("drpJD_Job_Category")

it is null.

how can that be?


Ignacio Machin ( .NET/ C# MVP ) said:
if i look at the page's code you're right it did get renamed because it's
coming from a user control, however take a look at the time of debugging,
just to show i'm not crazy here's the debug Immediate results:
?td.Controls[0]
{System.Web.UI.WebControls.DropDownList}
[System.Web.UI.WebControls.DropDownList]:
{System.Web.UI.WebControls.DropDownList}
AppRelativeTemplateSourceDirectory: "~/"
BindingContainer: null
ClientID: "drpJD_Job_Category"
Controls: {System.Web.UI.EmptyControlCollection}
EnableTheming: true
EnableViewState: true
ID: "drpJD_Job_Category"
NamingContainer: null
Page: null
Parent: {System.Web.UI.WebControls.TableCell}
Site: null
SkinID: ""
TemplateControl: null
TemplateSourceDirectory: "/hrrc"
UniqueID: "drpJD_Job_Category"
Visible: true
?td.FindControl("drpJD_Job_Category")
null

:


hey all,
i've added a dropdownlist object into tableCell td in my code
further down the code
i inspect the td.Controls
and i can see the the dropdownlist bright as day.
however, when i try to do
td.FindControl('id')
it returns null?
any ideas off the top why this may be?

Take a look at the page's code and see if the control was renamed, it
might happens that the control is renamed if it's inside a grid (or
any list control for that matter). If so you need to search using the
ClientId- Hide quoted text -

- Show quoted text -

Hi,

I fail to see what you want me to see.Sorry.

You know now the problem, the control is being renamed, either you
save the name of the control (by using ControlClientId) or you have to
search it by type, you could transverse the controls, looking for the
one you need.

Usually I keep the name of the controls I need using a
CommandArguments (I prefer to using OnCommand over OnClick)
 
requesting 2nd look at post above, or could i post a new post pointing to
this one for a possible 2nd look at this issue.

rodchar said:
well, as i showed in the debugging output above i'm doing a

?td.Controls[0]

and it finds the object i'm looking for, however, if i say

?td.FindControl("drpJD_Job_Category")

it is null.

how can that be?


Ignacio Machin ( .NET/ C# MVP ) said:
if i look at the page's code you're right it did get renamed because it's
coming from a user control, however take a look at the time of debugging,
just to show i'm not crazy here's the debug Immediate results:
?td.Controls[0]
{System.Web.UI.WebControls.DropDownList}
[System.Web.UI.WebControls.DropDownList]:
{System.Web.UI.WebControls.DropDownList}
AppRelativeTemplateSourceDirectory: "~/"
BindingContainer: null
ClientID: "drpJD_Job_Category"
Controls: {System.Web.UI.EmptyControlCollection}
EnableTheming: true
EnableViewState: true
ID: "drpJD_Job_Category"
NamingContainer: null
Page: null
Parent: {System.Web.UI.WebControls.TableCell}
Site: null
SkinID: ""
TemplateControl: null
TemplateSourceDirectory: "/hrrc"
UniqueID: "drpJD_Job_Category"
Visible: true
?td.FindControl("drpJD_Job_Category")
null

:



hey all,
i've added a dropdownlist object into tableCell td in my code
further down the code
i inspect the td.Controls
and i can see the the dropdownlist bright as day.
however, when i try to do
td.FindControl('id')
it returns null?

any ideas off the top why this may be?

thanks,
rodchar

Take a look at the page's code and see if the control was renamed, it
might happens that the control is renamed if it's inside a grid (or
any list control for that matter). If so you need to search using the
ClientId- Hide quoted text -

- Show quoted text -

Hi,

I fail to see what you want me to see.Sorry.

You know now the problem, the control is being renamed, either you
save the name of the control (by using ControlClientId) or you have to
search it by type, you could transverse the controls, looking for the
one you need.

Usually I keep the name of the controls I need using a
CommandArguments (I prefer to using OnCommand over OnClick)
 

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

Back
Top