Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET - Separation of concerns
    primarykey
    data
    text
    <p>Imagine the following scenario - we have Page1 which contains controls Control A and Control B.</p> <p>Say Control A has a button, and on the click of this button we want Control B to react. But we want to do this in an abstract fashion, i.e. we can't have Control B knowing anything about Control A, and vice versa.</p> <p>That way we can develop these controls in isolation, and drive them by unit-testing.</p> <p>Now, I thought I had the solution, just want to know what you guys think of it.</p> <p>On Control A's button click, I put a 'message' on the Session, i.e. Session["MESSAGES"] = "ControlA_Click".</p> <p>In Page1, on the Page_LoadComplete(), I put a call to ProcessMessages, which looks like this:</p> <pre><code> List&lt;Message&gt; messages = SessionMessages.GetMessageList(Page); foreach(Message m in messages) { //Get Controls ControlA controlA = FindControl("controlA") as ControlA; controlA .ProcessMessage(m); ControlB controlB = FindControl("controlB") as ControlB; controlB.ProcessMessage(m); } </code></pre> <p>in ControlB's ProcessMessage() method, we can react to the messages that ControlB is interested in, like so:</p> <pre><code> if (m.MessageName == SessionMessages.C_MESSAGE_SEARCH) { this.Visible = true; } </code></pre> <p>To me, this seems to work. It allows us to develop these controls completely separately from eachother, while still allowing for inter-control-communication at an abstract level.</p> <p>The only thing I can think of that might bring this crashing down is <em>perhaps</em> the ASP.NET life-cycle in relation to Pages and User Controls. The way I figure it though is that ALL events should have been processed on the controls before Page_LoadComplete() is called on the owning Page.</p> <p>Thoughts?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload