By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

find control in user control in master page

P: n/a
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$D ataList1$LinkButton1")

Any help will appreciated kindly.
Salim
Jul 23 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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


"Salim" <sa****@operatech.com.trwrote in message
news:uR**************@TK2MSFTNGP05.phx.gbl...
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$D ataList1$LinkButton1")

Any help will appreciated kindly.
Salim
Jul 23 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.