tags:

views:

26

answers:

2

I've seen in quite a few examples of asp.net ajax client side script the following:

function fHelloWorld(source, eventArgs)
{

}

If I run an alert on the source it's returned as an object. Can I use this to access what called the function? And if so how? i've tried things like

source.id;

Without luck

+1  A: 

The best advice that I can offer is, given an object, enumerate over the properties and write them out, including their values to the page. Then inspect the property values and will surely find out if such a property exists. You could also use Firebug, Fiddler2 or host of other tools to inspect the object.

Here's an example

function pageLoad(sender, args) {

// add function to the PageRequestManager to be executed on async postback initialize
var prm = Sys.WebForms.PageRequestManager.getInstance();
      prm.add_initializeRequest(InitializeRequest);   
}


function InitializeRequest(sender, args) {
    // Display loader gif when async postback initialized by element_in_question
    if(args._postBackElement.id === 'id_of_element_in_question' {              
        $get('ajax-loader').style.display = 'inline';
    }         
}
Russ Cam
A: 

Run the page with Firefox & Firebug, set a breakpoint inside your function, and inspect the source object interactively.

You can also display the object with console.log to get an object inspection hyperlink:

function fHelloWorld(source, eventArgs)
{
  console.log("%o", source);
}
orip