This is a migrated thread and some comments may be shown as answers.

Client-side DOM reference after AJAX update

2 Answers 38 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Albert Shenker asked on 12 Feb 2009, 03:58 AM
I have a rad grid with a template column. The template column contains a div element which I use as a toggle to show/hide some content. I set the onclick attribute for the div tag in the grid's ItemDatabound event. The div tag's clientId is passed to the following javascript function and I have domething along the lines of :

function toggleOfferItem_CSOC(divClientId)  
        {  
            var div = document.getElementById(divClientId);  // this is null after ajax update

When the page first loads and the grid is bound, everything works fine. Clicking on the div runs the javascript funciton and it does it's work. However, if I update the page with Ajax (the grid doesn't get rebound), then I get a null reference for the div within the javascript function. It would seem that the ajax update is changing the DOM structure of the page and since the grid isn't rebound, the Client ID which is passed to the javascript function is no longer valid.

So... is there a way to modify my javascript function to take this change into account?

2 Answers, 1 is accepted

Sort by
0
Accepted
SamJ
Top achievements
Rank 1
answered on 12 Feb 2009, 07:09 AM
HI,

Can you check if it is different when ajax is disabled?
I would suggest you to assign the div onclick attribute on grid ItemCreated as it is fired on each page load.

Regards,
SamJ
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 12 Feb 2009, 07:41 AM
I tried your suggestion and moved the div initialization code to the grid ItemCreated event. That seems to do the trick. Thanks for your help!
Tags
Ajax
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Answers by
SamJ
Top achievements
Rank 1
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Share this question
or