Controls traversing

Discussion in 'ASP .Net' started by abcd, Dec 2, 2009.

  1. abcd

    abcd Guest

    Let me know if you know this.

    I have Aspx page with below control structure.

    AjaxTabContainer
    - ReceiptPanel
    ? Literal
    ? ReportViewer

    - EmailPanel
    o UserControl
    ? TextBox1
    ? TextBox1
    ? Button

    I want to access the ReportViewer control from Button action.

    I tried

    var rptVw = (ReportViewer)
    Parent.Parent.Parent.Controls[0].Controls[1].Controls[1];

    This works but looks ugly. Also I dont want to search the control by its ID.
    [I dont want hardcoding so that it can be used multiple places]

    I am blind at this moment. Do you see efficient way to reach to
    ReportViewer, from the button action.
     
    abcd, Dec 2, 2009
    #1
    1. Advertising

  2. "abcd" <> wrote in
    news::

    > var rptVw = (ReportViewer)
    > Parent.Parent.Parent.Controls[0].Controls[1].Controls[1];
    >
    > This works but looks ugly. Also I dont want to search the control by
    > its ID. [I dont want hardcoding so that it can be used multiple
    > places]
    >
    > I am blind at this moment. Do you see efficient way to reach to
    > ReportViewer, from the button action.


    You can make this a bit prettier by "asking" the control for its id and
    emitting the JavaScript that "finds" it. It is a more maintainable solution
    than Parent.Parent.Parent.Controls[0].Controls[1].Controls[1], as altering
    the page may end up with the ReportViewer with a different ordinal value.

    Other than that, I am not coming up with any brilliant ideas at the moment.

    Peace and Grace,

    --
    Gregory A. Beamer (MVP)

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Dec 2, 2009
    #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. steven
    Replies:
    6
    Views:
    973
    steven
    Aug 27, 2003
  2. Asad

    XML - traversing in VB

    Asad, Apr 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    619
    Matt Berther
    Apr 16, 2004
  3. Replies:
    4
    Views:
    697
  4. =?Utf-8?B?c2xpbV9uYWxkeQ==?=

    traversing a client directory in ASP.NET

    =?Utf-8?B?c2xpbV9uYWxkeQ==?=, May 10, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    835
    Scott M.
    May 12, 2005
  5. df
    Replies:
    0
    Views:
    347
Loading...

Share This Page