Controls traversing

A

abcd

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.
 
G

Gregory A. Beamer

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

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top