Access user control from another user control

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Hi

I have a scenerio where I need to fire an event in one user control, by
clicking a button in another user control. However, I need to do this
without using an event code in the .aspx file. Is this possible?

For example:

Webform1.aspx contains 2 user controls:
1. SearchBox (some textboxes and a button) and
2. SearchResults (some search results dependent on the textbox values)

An event (such as a Sub or Function) in SearchResults needs to be fired when
the SearchBox button is clicked.

Any ideas gratefully received...

Dan
 
Hey
You can have public methods for this purpose. and can access them from any user control you have in your form

thanks
 
Hi, Dan,

The dirty solution is to call FindControl on the Page property of the
SearchBox class. You should pass the id of the SearchResults control. Then
you need to cast the returned reference to the SearchResults class and call
the methods you want.

A better solution is to create an interface. You can make it expose the
method in question or you can simply return the reference to the
SearchResults control. Then implement this interface in the page class. Then
in the handler of the button click in the SearchBox class you cast the Page
property to this interface and do whatever you need.

Hope this helps
Martin
 
Back
Top