Communication between controls
Can anybody please guide me on communication between controls..for example i have the following base control
public partial class BaseWebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
from this control i derive two controls..such as one control that displays user data from a grid view..and another control that contains a dropdownlist with autopostback to true.
Now i want to put these controls together in one page..so one control would be populating the data and when button of the second control is clicked it would call a function such as DataBind of the first control and do some sorting based on dropdownlist selection.
I would appreciate any help in this.
Re: Communication between controls
It makes no difference what these controls are or what class they're derived from. Every instance of every class is a distinct object and needs to communicate with every other distinct object in the same way. If you want to do something when something happens, that ALWAYS means raising and handling an event. This means that your control with the button must raise an event when its button is clicked. That event is then handled, either by the other control or by the page itself, and then the appropriate action taken. I would assume that you've handled plenty of events before so you should have that part down. If you haven't declared and raised an event before then you should read up on that.
http://search.msdn.microsoft.com/sea...ng+events+C%23
Re: Communication between controls
Thanks for the tip, i would look into it. Can you give me a short example, like the button would raise the event when clicked and that would be handled by the other control.