Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jacques van der Kleij 7 posts 38 karma points
    Aug 28, 2009 @ 15:05
    Jacques van der Kleij
    0

    Communicating usercontrols

    In general I would like to know from anybody how you can let two usercontrols on the same page communicate with each other. I have seen so many examples and solutions, but none of them let my two usercontrols be aware of the fact that the other one had a request or information for the other one.


    In short: in the first usercontrol the user fills in a textbox and submits this information with a button to the database. At the same time the other usercontrol should respond to this action and show the - let's say - new total of this particular item in the database automatically. How can I trigger the seond usercontrol to do this?!?

    Should you use the masterpage? If it doesn't have a code-behind, should you create that? Why doesn't Page.FindControl(...) which seems to be the key to the solution work as promised anyware?

    It can be done by clicking the submit button twice, but that is something you cannot ask a user to do!

    Thanks in advance!

    Jacques

    By the way: we use Windows Server 2008, IIS 7, ASP.NET 3.5 and the latest Umbraco version

  • Jonathan Meuth 5 posts 25 karma points
    Aug 28, 2009 @ 21:00
    Jonathan Meuth
    0

    I believe you should be able to look through the Page's controls that the control belongs to.  If you find the type of control you are looking for, you can typecast that control to your control type and use it.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 29, 2009 @ 08:44
    Richard Soeteman
    101

    Hi Jacques,

    I think you have 2 options:

    1. Use events. You can raise an event each time a record is updated and the "Calculate Total Usercontrol" can act on that and calculate and display the new total,but you still have an issue subscribe to these events.

    2. In the "Calculate Total" usercontrol don't display the total on the Load Event but use the PreRender event. The button Click event that is raised when the user submits the data is fired after the Load event and that's why you don't see the results yet. On my weblog you'll find a poster about the Page Lifecycle (intro is in Dutch but I'm sure you can read that :P)

    Cheers,

    Richard

     

  • Chris Koiak 700 posts 2626 karma points
    Aug 29, 2009 @ 09:15
    Chris Koiak
    0

    Jacques,

    Richards options sound ideal.

    Try and think about it differently. You don't want your controls to communicate with each other, you want one control to update the state (maybe session variable?) and the second control to respond to this change.

    Cheers,

    Chris

     

  • Jacques van der Kleij 7 posts 38 karma points
    Aug 29, 2009 @ 16:37
    Jacques van der Kleij
    0

    Jonathan, Richard and Chris!

    I thank you all for responding to my cry for help. But in particular I have to thank you, Richard, for your 'pre_render' suggestion.

    'What's in a name!?' As soon as I changed my 'Page_Load' into 'Page_PreRender' things started working as I had planned.

    Not that I have seen the light, but that is not my concern, right now. I have seen a lot and I have learned some things over the past few days, but I am happy that my Synergy4U partner forced me to make my development problems known on the Umbraco forum.

    Thanks again and hopefully (not?) till next time!

    Jacques

Please Sign in or register to post replies

Write your reply to:

Draft