Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Accessing controls across user controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vince - 27 Mar 2008 01:26 GMT
Hi,

I have 3 user controls and a parent page which contains all of them.

In control A, I would like to access a datagrid in control B but I
have no idea how I would do it.

The only work around I can think of, is to expose the datagrid via a
property of control B, but even then, I have no idea how I would let
control A know of its existance unless i create a function and pass it
in.

Are there any neat ways of doing this?
Michael Nemtsev [MVP] - 27 Mar 2008 01:39 GMT
Hello Vince,

Using property to expose data from user controls is a standard way.
But you can also store the control.ClientID in sessions and then find this
control by enumerating the page controls

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

V> Hi,
V>
V> I have 3 user controls and a parent page which contains all of them.
V>
V> In control A, I would like to access a datagrid in control B but I
V> have no idea how I would do it.
V>
V> The only work around I can think of, is to expose the datagrid via a
V> property of control B, but even then, I have no idea how I would let
V> control A know of its existance unless i create a function and pass
V> it in.
V>
V> Are there any neat ways of doing this?
V>
Vince - 27 Mar 2008 02:08 GMT
> Hello Vince,
>
[quoted text clipped - 23 lines]
> V> Are there any neat ways of doing this?
> V>

So i would expose control B datagrid via a property, and then create a
function in control A code behind to say something like
ControlBDataGridSet(dataGrid)?

This seems silly. What If I had to access many controls?

Also, i make it a habbit never to use session.

Surely there would be a better way for something this common.

If not then so be it.

Thanks anyway
Michael Nemtsev [MVP] - 27 Mar 2008 12:46 GMT
Hello Vince,

No, I meant that expose the data, not the controls. If you have a datagrid
in user control for example, then expose the data property to have the data
for binding the datagrid. not the datagrid.

But if y need to have access to the control directly then use FindControl
method for this with control clientID

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

V> On Mar 27, 11:39 am, Michael Nemtsev [MVP] <nemt...@msn.com> wrote:
V>
>> Hello Vince,
>>
[quoted text clipped - 27 lines]
>> V> Are there any neat ways of doing this?
>> V>
V> So i would expose control B datagrid via a property, and then create
V> a function in control A code behind to say something like
V> ControlBDataGridSet(dataGrid)?
V>
V> This seems silly. What If I had to access many controls?
V>
V> Also, i make it a habbit never to use session.
V>
V> Surely there would be a better way for something this common.
V>
V> If not then so be it.
V>
V> Thanks anyway
V>

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.