find control in user control in master page

Discussion in 'ASP .Net' started by Salim, Jul 23, 2007.

  1. Salim

    Salim Guest

    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, Jul 23, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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. Justin Gengo, Jul 23, 2007
    #2
    1. Advertising

  3. Salim

    SerpentKiss2010

    Joined:
    Apr 6, 2011
    Messages:
    2
    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";
     
    SerpentKiss2010, Jun 15, 2011
    #3
    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. Electrified Research
    Replies:
    5
    Views:
    2,466
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 11, 2005
  2. Doug McCann
    Replies:
    1
    Views:
    1,028
    William Brogden
    Aug 5, 2004
  3. Zeba
    Replies:
    1
    Views:
    494
    Mark Rae
    Feb 22, 2007
  4. Nathan Sokalski
    Replies:
    25
    Views:
    1,436
    Nathan Sokalski
    Mar 4, 2010
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,493
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page