Checking if an ASP page is dirty before asking user if they want to leave
<p>I have a ASP.NET form and it has a bunch of user inputs, text boxes, checkboxes, etc. I need to be able to check if the user has made an edit on the form without saving and if so prompt then beforeunload. </p>

<p>I have a dirty flag that set once the user edits one of the text boxes. If they save the data on the form then I reset the flag. Therefore the flag should only ever be set when the user edits but has not saved.</p>

<p>I then use this flag to decide whether or not to prompt the user “Are you sure you want to leave this page?”</p>

<p>Code snippet:</p>

<pre><code>var _isDirty = false;

    $(function () {
        try {
                $("#MainContent_txtSometextBox").change(function () {
                    _isDirty = true;
                });
            } catch (e) { }
        });
</code></pre>

<p>The problem is I don’t want to have to set this on every control. Is it possible to set it at a page level? I don’t think it will be that easy as we also have custom user controls on the page.</p>
