Shared User Control - WCSF 2.0

Jan 1, 2008 at 1:26 PM
Hi all and a Happy New Year,

I need some help wiring up a 'shared user control', or possibly fixing whatever wrong assumption I've made about it.

I created the user control (UC) using the Add User Control (with Presenter) in a sub-folder of the Shared folder on the website, i.e. the presenter is in the Shell module. I've consumed a Model foundation module and haven't implemented a Controller for the UC as such.

Then, I added the user control to the default page/view of a Business Module. All appears fine, that is the user control does what I expect when the Default Business Module page renders and I interact with it.

What I'd like to have happen though (and this isn't working) is for the UC to raise an event the Default page/view of the Business Module can capture.

As far as I can work out the event is never raised, that is it is null, from within the UC as it doesn't detect any listeners for the event.

The question is Where/How is the best place to implement the event receiver in the Business Module and how do I access the shared UC event provider?

Happy to answer questions to clarify the situation, but unfortunately can not provide the code for 'privacy' reasons.

Thanks
Leon
Jan 2, 2008 at 7:31 AM
Edited Jan 2, 2008 at 7:39 AM
Hi Happy New Year To You Too.

Well for wiring up events for UC, you simply need to write your delegate, event arg class in your bussiness module of in App_Code. Once your are done with it, you need to provide event of delegate type in UC class. Once that is done, you need to take reference of your UC in the default page of your bussiness module. By taking reference of your UserControl in the default page either you can add your UserControl at page construction or by using LoadControl method to load your UserControl at runtime. Now once your control is added to your default page just you add your event handler there in the page.


Thanks
Abhijit

Leon1234 wrote:
Hi all and a Happy New Year,

I need some help wiring up a 'shared user control', or possibly fixing whatever wrong assumption I've made about it.

I created the user control (UC) using the Add User Control (with Presenter) in a sub-folder of the Shared folder on the website, i.e. the presenter is in the Shell module. I've consumed a Model foundation module and haven't implemented a Controller for the UC as such.

Then, I added the user control to the default page/view of a Business Module. All appears fine, that is the user control does what I expect when the Default Business Module page renders and I interact with it.

What I'd like to have happen though (and this isn't working) is for the UC to raise an event the Default page/view of the Business Module can capture.

As far as I can work out the event is never raised, that is it is null, from within the UC as it doesn't detect any listeners for the event.

The question is Where/How is the best place to implement the event receiver in the Business Module and how do I access the shared UC event provider?

Happy to answer questions to clarify the situation, but unfortunately can not provide the code for 'privacy' reasons.

Thanks
Leon

Jan 2, 2008 at 7:56 AM
Hi,

For more clearner explanation visit link below
http://abhijitcb.blogspot.com/2007/12/interacting-between-two-different-user.html

Thanks
Abhijit


Leon1234 wrote:
Hi all and a Happy New Year,

I need some help wiring up a 'shared user control', or possibly fixing whatever wrong assumption I've made about it.

I created the user control (UC) using the Add User Control (with Presenter) in a sub-folder of the Shared folder on the website, i.e. the presenter is in the Shell module. I've consumed a Model foundation module and haven't implemented a Controller for the UC as such.

Then, I added the user control to the default page/view of a Business Module. All appears fine, that is the user control does what I expect when the Default Business Module page renders and I interact with it.

What I'd like to have happen though (and this isn't working) is for the UC to raise an event the Default page/view of the Business Module can capture.

As far as I can work out the event is never raised, that is it is null, from within the UC as it doesn't detect any listeners for the event.

The question is Where/How is the best place to implement the event receiver in the Business Module and how do I access the shared UC event provider?

Happy to answer questions to clarify the situation, but unfortunately can not provide the code for 'privacy' reasons.

Thanks
Leon

Jan 2, 2008 at 10:47 AM
Abhijit,

I've managed to make it work using your suggestion, thank you. I was missing (as per your example) this step: "_pagingControl = (PagingControl) LoadControl("Paging.ascx");" Or more accurately my version of this. I wasn't adding the 'receiver' to the right control.

The one thing I'm struggling with from an architecture perspective is that this Event raising/handling pair is taking place at the View level, but am thinking that it should be happening at the Presenter/Controller level?

So, in short I have working code, but am not sure about its 'correctness' in the overall model for the WCSF. Anyone care to comment?

Thanks
Leon
Jan 2, 2008 at 1:54 PM
Edited Jan 2, 2008 at 2:50 PM
Leon,

Its my pleasure that my example helped to make your things working. Well I am not very sure but your UC is a sender in this case and your page is your receiver of the event. So ideally your page should use presenter and controller to take action for events occuring on your control for your case.

Thanks
Abhijit


Leon1234 wrote:
Abhijit,

I've managed to make it work using your suggestion, thank you. I was missing (as per your example) this step: "_pagingControl = (PagingControl) LoadControl("Paging.ascx");" Or more accurately my version of this. I wasn't adding the 'receiver' to the right control.

The one thing I'm struggling with from an architecture perspective is that this Event raising/handling pair is taking place at the View level, but am thinking that it should be happening at the Presenter/Controller level?

So, in short I have working code, but am not sure about its 'correctness' in the overall model for the WCSF. Anyone care to comment?

Thanks
Leon