Dotneteers.net
All for .net, .net for all!

Disabling buttons/lists/etc when executing ASP.NET AJAX request

Just drop it in your page before the </body> tag:

    <script language="javascript" type="text/javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();

        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);

        var oldClass = "";
       
        function InitializeRequest(sender, args) {
            var postBackElement = $get(args._postBackElement.id);
            if (postBackElement != null) {
                postBackElement.disabled = true;
                oldClass = postBackElement.className;
                postBackElement.className = postBackElement.className + " disabled";
            }
        }
       
        function EndRequest(sender, args) {
            var sourceElement = $get(sender._postBackSettings.sourceElement.id);
            if (sourceElement != null) {
                sourceElement.disabled = false;
                sourceElement.className = oldClass;
            }
            oldClass = "";
        }
    </script>

And add this to your CSS (you may differentiate this among various tags like img.disabled for imagebuttons or input.disabled for textboxes etc.):

.disabled
{
    FILTER: alpha(opacity=70);
    BACKGROUND-COLOR: gray;
    opacity: 0.7
}

Just be carefull if you change the class of the element in question (that originated the ajax postback) to register a client script block to set oldClass to the new value as well, otherways it would be overwritten.


Posted Apr 08 2009, 01:25 PM by petersm

Comments

SKOROZSI.NET wrote links for 2009-04-10
on Fri, Apr 10 2009 23:04

links for 2009-04-10

Add a Comment

(required)  
(optional)
(required)  
Remember Me?