find control in user control in master page

  • Thread starter Thread starter Salim
  • Start date Start date
S

Salim

Hi,

I'm trying to get UniqueID of a linkbutton.

I have 2 web user controls.
And a master page.

In fisrst web user control there is a datalist.
In datalist ItemCreated event, I try to find a linkbutton control which is
in the second web user control and in another datalist.
My code is like:

this.Page.Master.FindControl("ctl00$UserControl2$DataList1$LinkButton1")

Any help will appreciated kindly.
Salim
 
Salim,

It looks like you are using the ClientID instead of the server side ID. All
controls have a "regular" server side ID (The ID you see in the properties
window for the control) and a ClientID which is rendered when the html is
output. When finding a control from within the code-behind you should use
the server side ID. Which based on the ClientID should be: LinkButton1.

If you use this it should work:
this.Page.Master.FindControl("LinkButton1")

It's also possible though, that the LinkButton is contained inside another
control (nested) which it looks like it may be (your "DataList"). So if that
is the case you'll need to find the top-level control on the master page and
then do a find control inside each control moving into each one until you
get to the control you need.

(i.e.

DataList MyDataList = (DataList) this.Page.Master.FindControl("DataList1");
LinkButton MyLinkButton = (LinkButton)
MyDataList.FindControl("LinkButton1");

Regards,

--
S. Justin Gengo, MCP
justin@aboutfortunate[-NoSpam-].com

Free code library at:
www.aboutfortunate.com
 
Back
Top