Passing Objects between Web User Controls

R

Richard Payne

Hi

I am after what is the best/simplest way to pass objects between Web User
Controls which doesn't use the session object.

Regards

Richard
 
B

bloomfield

I do not know if this is the simplest way:

Make a PageBase derived from Page and put a member of type Object in it
(or anything that fits your needs).
Derive every page in your application from PageBase
From a web user control you have the access to the Page (you must cast
it to the PageBase) and so you can put/get something to/from there.
 
J

John Saunders

Richard Payne said:
Hi

I am after what is the best/simplest way to pass objects between Web User
Controls which doesn't use the session object.

It's probably a bad idea to pass objects between web user controls. Why
should they even know about each other?

On the other hand, the page they are located within should know about all
the user controls within it. So let the page take values from one user
control and pass them to the other. Use public properties on the user
controls to enable this.

The same goes for events. One user control should probably not raise events
for another user control to handle, since they shouldn't know about each
other. Let the page handle the event from user control A and then set
properties or call methods on control B.
 
S

Steven Cheng[MSFT]

Hi Richard,

In addition to bloomfield's sugguestion. I think if you just want to share
data between controls on the same page, I think the Page's ViewState is
also considerable. Since ViewState is a large storage for serializable
datas and will remain for all the requests for the same page.

#Understanding ASP.NET View State
http://msdn.microsoft.com/library/en-us/dnaspp/html/viewstate.asp?frame=true

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top