Please see my comment to the question.
This is not about determining where to echo. You should never determine that. The whole idea is wrong. This is a bright illustration of the problem we face when developers use one or another
design pattern or
architectural pattern. This is the case when the use of the pattern clouds the vision of the design itself, which may not happen with people doing the design. The use of patterns is intended to save time on design, but the real effect is misleading.
In your case, you use such a well detailed architectural pattern as MVC (or think that you use it), but get completely lost in much more basic and fundamental design issue, in a way not only totally contradicting to MVC, but to much more basic principles, effectively, to the idea of event-oriented UI in general. You can solve the problem your way, but it would defeat the purpose not only of all patterns, but all the technologies you employ, looking like this:
Sergey Alexandrovich Kryukov - Professional Profile - CodeProject[
^].
So, please, no offense. I'm writing this only because you need to understand: when you face your problem, your first step should never be solving it. Instead, you first need to realize
where you are.
To realize it, it's important to get some design concepts. First of all, this is related to
inversion of control:
Inversion of control[
^].
In tern, this is related to
dependency inversion principle, one of
SOLID OOP principles:
Dependency inversion principle[
^],
SOLID (object-oriented design)[
^].
All the event-oriented UI is based on IoC. Armed with conceptual views, look at your UI design. You should not look where to output some data. Instead, you should handle the even of selection of the heating type by the user itself. Roughly put, it should be some JavaScript of this sort:
myHeatingSelector.onselected =
function(eventInstance) {
if (...)
myTextBox.value = getValueFromSelectedSource;
else if (...)
myOtherControl.value = getValueFromSomewhere;
};
Are you getting the idea? I cannot give you further detail; they depend on your UI detail, this is just the illustration.
But I would rather re-think the idea of using separate text boxes. If a user selects only one heating source at a time, just one output element might be enough. Not only it can make your code more elegant, but the use may get less cluttered page. But it depends, needs some UI design review.
Further decision depends on what you want to get from the server side and when you want to postback. Depending on that you can preload all the page data from the first HTTP response; one known technique is filling in the set of hidden controls on the server side, ugly, but then you operate locally in pure JavaScript, by taking data from one or another control, processing it and showing where you want to see the result.
If you need to get some additional information from the server on each user's selection, you may need to use Ajax to send an HTTP request and retrieve data from HTTP response. In this case, your concern would be the performance of such handling.
And so on…
—SA