How tro use FindControl (C# or VB)

Discussion in 'ASP .Net' started by Paul, Feb 24, 2006.

  1. Paul

    Paul Guest

    I have an item in the aspx part of my page:

    <a id="PreviousPageNav" runat="server" >

    <asp:Image runat=server ID="PreviousImage"
    ImageUrl="~/Images/Nav/previous.gif" />

    </a>

    that I put in the header of a DataList.

    When it was outside of the Datalist, on the Code Behind, I accessed it like
    this:

    PreviousPageNav.HRef = String.Format(navigationFormat, StoreID, pageIndex -
    1);

    PreviousPageNav.Visible = (pageIndex > 0) ? true : false;



    But I can not seem to be able to access it once it is in the header of the
    DataList. Looking around, I see the FindControl method, but am usure on how
    to use it.

    Suggestions, please?



    Paul
     
    Paul, Feb 24, 2006
    #1
    1. Advertising

  2. I have never needed to modify the Controls in the HeaderTemplate before, but
    I think that you would simply do something like:


    YourDataListID.FindControl("PreviousPageNav").HRef=String.Format(navigationFormat,
    StoreID, pageIndex-1);


    The FindControl(ControlID) method returns a reference to the Control with
    ControlID, so you can basically use it in place of where you would normally
    just use ControlID. But I have never actually tried this with
    HeaderTemplates (although I have with the different ItemTemplates, so I
    expect it will be the same), so hopefully it will work. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Paul" <> wrote in message
    news:K6GLf.5$...
    >I have an item in the aspx part of my page:
    >
    > <a id="PreviousPageNav" runat="server" >
    >
    > <asp:Image runat=server ID="PreviousImage"
    > ImageUrl="~/Images/Nav/previous.gif" />
    >
    > </a>
    >
    > that I put in the header of a DataList.
    >
    > When it was outside of the Datalist, on the Code Behind, I accessed it
    > like this:
    >
    > PreviousPageNav.HRef = String.Format(navigationFormat, StoreID,
    > pageIndex - 1);
    >
    > PreviousPageNav.Visible = (pageIndex > 0) ? true : false;
    >
    >
    >
    > But I can not seem to be able to access it once it is in the header of the
    > DataList. Looking around, I see the FindControl method, but am usure on
    > how to use it.
    >
    > Suggestions, please?
    >
    >
    >
    > Paul
    >
    >
     
    Nathan Sokalski, Feb 25, 2006
    #2
    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. Sid
    Replies:
    4
    Views:
    590
  2. ad

    When need to use FindControl

    ad, Apr 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    446
    Karl Seguin
    Apr 28, 2005
  3. sck10
    Replies:
    6
    Views:
    19,861
    UdayGaikwad
    Oct 24, 2011
  4. =?Utf-8?B?TWlrZSBDb2xsaW5z?=

    Trying to use FindControl

    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Dec 22, 2006, in forum: ASP .Net
    Replies:
    11
    Views:
    609
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=
    Dec 23, 2006
  5. John Kotuby
    Replies:
    5
    Views:
    398
    John Kotuby
    Dec 12, 2007
Loading...

Share This Page