I am working on a set of ASP.NET applications using a master page. When I try to register a clientscript - an alert box for instance, in the Page_Load it works fine. However if I try to do the same from any method or event handler of the same class it doesn't. Also, it doesn't seem to matter which Register method you use, both work only in the Page_Load (for me).
I could not find another way so far to alert the user about exceptions and such from within the code (other than building a user control) and I figure in a similar situation other JavaScript codes won't execute either...for example one that would refresh an iframe content.
I'm wondering if there is a best practice to achieve a little more dinamic interaction between JavaScript and code behind?
What I mean is something that:
- can be called from anywhere in the codebehind
- UpdatePanels and MasterPages don't make it unreliable