Tuesday, 31 July 2012

Store some client-side data in request and respose object

1. Attach javascript object to the request

2. when that request is served by the server and response is sent back. At the same time I don't want to sent that attached object to the server with request and then receive it from the server, because it's not efficient - we can store that object on client side.

Assing Javascrip Object ( Function ) to request :






<script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
</script>

function beginRequestHandler(sender, args) {
            // get WebRequest object
            var request = args.get_request();

            // get button that invoked postBack
            var clickedButton = args.get_postBackElement();
            var customData = 
                {
                    requestStart : new Date(),
                    button : args._postBackElement
                };
            // modify WebRequest, assigning custom data to _userContext property
            request.set_userContext(customData);
        };

No comments:

Post a Comment