find control in user control in master page

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
 
S

S. Justin Gengo

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
 
Joined
Apr 6, 2011
Messages
2
Reaction score
0
1- Register my UserControl
<%@ Register src="UserControls/Login.ascx" tagname="Login" tagprefix="uc1" %>

2- Put User Control in MasterPage
<uc1:Login ID="Login1" runat="server" />

3- To Find Control in UserControl Just Write

TextBox txtEmail = (TextBox)Login1.FindControl("txtEmailSignin");
CheckBox chkRem = (CheckBox)Login1.FindControl("chkRemember");

txtEmail.Text="Any thing";
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top