Accessing controls across user controls

  • Thread starter Thread starter Vince
  • Start date Start date
V

Vince

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?
 
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>
 
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>

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


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>
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>
 
Back
Top