ASP.NET AJAX pageLoad() not firing (formerly: "with StyleSheetTheme, does with Theme?")

StackOverflow https://stackoverflow.com/questions/23496680

  •  16-07-2023
  •  | 
  •  

Pergunta

Updated - Title changed b/c StyleSheetTheme and Theme have nothing to do with it -- see answer for details.

I'm working on a page that has descended, through several years and a few intermediary stages, from another page that successfully uses the AJAX pageLoad() function to perform some (re-)initialization on full and partial postbacks.

The pageLoad() on this new page was not firing. A systematic comparison of the two pages (.aspx and .js files) eventually led me to a surprising (to me, anyway) difference that was causing the failure: the old page's @ Page directive specified a Theme="foo", whereas the new page's directive specified a StyleSheetTheme="foo". Changing StyleSheetTheme to Theme restores the triggering of the pageLoad() function.

In this new page I can live with the (non-overridable) Theme settings, so I don't actually have a problem that needs solving in this momemt, but I thought the behavior was not obvious and worth noting, and if someone has insight into the reason(s) StyleSheetTheme might block firing of pageLoad() I would like to know.

Foi útil?

Solução

Further investigation with the page referenced in the question as well as other similar pages revealed that the problem had nothing to do with changing between the StyleSheetTheme and Theme attributes of the @ Page directive. I changed the question/title to reflect this.

The actual reason the pageLoad() function was not being triggered in the particular Javascript file I was working on is that there was already another pageLoad() function defined in a separate Javascript file being used by the page, and it was the one being executed because it was included later and over-rode/replaced the one I was working on. I found this using a script debugger by locating the pageLoad handling within the ScriptResource.axd file (in function Sys$_Application$raiseLoad()) and following execution into the second, over-riding script file... Palm, meet forehead...

Takeaway points:

  • only one pageLoad() can operate at the page level without resorting to some kind of scheme to daisy-chain multiple scripts; I opted for this approach so each of my script files can add its own (re-)initialization to the chain without clobbering any that are already there
  • using the StyleSheetTheme attribute vs the Theme attribute had nothing to do with my problem
  • try to be (even more) careful to ensure clear and clean tests before posting to SO... I thought that I had done a simple A/B test of the page directive attributes and that it had solved the problem, but upon discovering the true cause I went back to review the screen-captures (I use for time-tracking) and discovered that I had made two changes, not just one, before observing the change in behavior. It was the other change (removing another Javascript file from my page) that had fixed it, but during an interruption between the changes and final testing I forgot that I'd done it
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top