views:

232

answers:

4

How to send variables from one user control to another on the same asp.net web page during a postback without using session variables? Hidden fields could be an option, anything else?

+2  A: 

In general, controls on a page should know very little about each other.

However, the page knows about them both. Have a property on the first control that the page will read, then the page will use that value to set a property on the second control.

John Saunders
A: 

HttpContext.Items? Public properties (feels dirty) == ((OtherControl ) this.Control.Page.FindControl("OtherControl")).PropertyName?

A: 

Each control can have properties that are retained using viewstate, on page load assign the property to a variable on the page, the other control can be set using this

Stuart
+1  A: 

User controls should be independent entities. The best way to communicate among them is by using events. The containing page is responsible for subscribing to and handling events, and coordinating actions among user controls.

Jamie Ide
do you have a link to sample? the topic makes sense but implementation is not easy for me
Tony_Henrich
Have a look at my reply to this question: http://stackoverflow.com/questions/839365/best-way-to-display-search-results-on-the-same-page-as-the-search-control-in-asp
Jamie Ide