views:

61

answers:

2

Is there any way to launch a JS function after a dataGrid launches its ItemDataBound event?

I've tried adding a JS block to the ItemDataBound function like:

protected void itemDataBound (e sender, arguments args)
{
    ClientScript.RegisterStartupScript(typeof(string),"test","alert('testing');",true);
}

but it did nothing.

Am I missing something?

+2  A: 

After reading your question, it seems you have things a little mixed up... please excuse me if i have misinterpreted and you already know this stuff.

Can we straighten out the terminology you are using? I assume you mean to say:

How can i [attach | insert] a piece of javascript into the page when the grid ItemDataBound event fires?

If this is what you mean, then skip to the following paragraph. If it isn't and you were expecting the javascript to be executed immediately, then it can't: you are on the server, javascript runs on the client.

With your test start up script, it also will not run when it is loaded as part of an ajax callback - your page has already loaded, all you are doing is replacing part of it.

When injecting scripts in the ItemDataBound event, the normal thing to do is to attach a piece of script to an event of an HTML element - you could just inject a piece of script in to the page, but you will inject it for every item that is databound (unless you test for its presence first), and even then it is useless unless you either directly call it or have something trigger it.

Here is a good example to get you started, there is a load more out there which you can find with a quick google.

slugster
You understood the question correctly. Thanks for the effort. It seems like I can only inject "onmouseover" / "onclick" events to the items. I'm trying to inject an "onload" script.
Faruz
IIRC, if you start the ajax postback from javascript, then you have the option of specifying a javascript callback function that is called when the ajax request is complete - i would look into leveraging that.
slugster
+1  A: 

Found a work around using UpdatePanelAnimationExtender and ScriptAction

Faruz