Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Controls traversing (http://www.velocityreviews.com/forums/t707352-controls-traversing.html)

abcd 12-02-2009 07:05 AM

Controls traversing
 
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.


Gregory A. Beamer 12-02-2009 03:12 PM

Re: Controls traversing
 
"abcd" <abcd@abcd.com> wrote in
news:B060C593-4764-4B2C-B8CB-D79654928234@microsoft.com:

> 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! |
*******************************************


All times are GMT. The time now is 06:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.