Too much redundant javascript code
<p>On my asp.net pages i need to control for Dirty controls. I'm not that good in javascript so i found a solution on the internet for doing that by doing so : </p>

<pre><code>&lt;script type="text/javascript" language="javascript"&gt;
    //Demo of completely client side dirty flag.

    function setDirty() {
        document.body.onbeforeunload = showMessage;
        //debugger;
        document.getElementById("DirtyLabel").className = "show";
    }

    function clearDirty() {
        document.body.onbeforeunload = "";
        document.getElementById("DirtyLabel").className = "hide";
    }


    function showMessage() {
        return ""
    }

    function setControlChange() {
        if (typeof (event.srcElement) != 'undefined') {
            event.srcElement.onchange = setDirty;
        }
    }

    document.body.onclick = setControlChange;
    document.body.onkeyup = setControlChange;

    window.onunload = function (sender, eventArgs) {
        if (window.opener != null) {
            window.opener.ClearBlocker();

            if (window.opener.TempClientReturnFunction != null)
                window.opener.TempClientReturnFunction = window.opener.ReturnFunction;
        }
    }
&lt;/script&gt;
</code></pre>

<p>but if i have like 7 pages where i need to control for Dirty Controls, its gonna be too much redundant code. Are there any ways to create some class/library from where i can just call functions or are there maybe even smarter way of doing that? </p>
