Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts

Wednesday, 22 August 2012

Call back from client side to server side

//Javascript
__doPostBack('<%=btnAdvanceSearch.ClientID %>', 'Click');

//In Page_Load Event Find

 if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"].ToString).Equals("Click"))
            {
                             //Implement Code...
            }

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);
        };

Tuesday, 1 May 2012

Ajax Class in ASP.Net Client

Two main Microsoft Ajax Library classes that raise events during the client life cycle of a WebForms based page are the Application and PageRequestManager classes.

Events (like page_load, page_Init etc....) that are raised by the Application and PageRequestManager classes.

The Microsoft Ajax Library also contains classes for adding, clearing, and removing handlers for DOM element events
           Application is handel the page and controls events (like page_load, page_Init etc....)  
           PageRequestManager  is handel server postback and  asynchronous postbacks object ( like Request, Respose etc... )

Add or Remove handlers for events raised by the Application and PageRequestManager classes,
 Example
                       function MyTest() // Declare the handler
                              { alert('Harshad Patel');
                              }
                             Sys.Application.add_init(MyTest) // add 'MyTest' to Page_Init Event
                             Sys.Application.remove_init(MyTest) // remove 'MyTest' to Page_Init Event
An instance of the PageRequestManager class is automatically available in the browser (Client Side)
like
               var PM = Sys.WebForms.PageRequestManager.getInstance();