views:

19

answers:

1

I have a web form used for importing data from a CSV file. It contains a result panel and a result label, which either show a success message or an error message after the import process. Let me say here I know the page should not be doing the import, but this is legacy code and the client expects only small changes.

My problem is that the result message (label) retains it's previous content and visibility during the next import process, because clearing it during Page_Load or at the beginning of the import method only has effect when the import method is complete and thus the postback is complete.

At the moment, the only solution I can see is to move the import code into a separate class (as it should be), call the import method asynchronously, clear the result message, and thne set then result message when the complete or error callback from the import process is called.

Is there any other way?

+1  A: 

In client-side javascript, add an onclick handler to the submit button which hides (or removes) the status message before submitting the form.

For example:

<script>
function submitForm() {
    var e = document.getElementById("theErrorMessage");
    e.style.display = 'none';
    var theForm = document.getElementById("theForm");
    theForm.submit();
    }
</script>

<!-- in your HTML -->
<input type="button" onclick="submitForm();" text="Import" />
egrunin
Thank you sir! Such an obvious but elegant solution that would have escaped me for days.
ProfK