NC01:
And as for Page_Load being executed on AJAX Callbacks, I think that you are mistaken. Page_Load is ONLY executed on a FULL PostBack.
Actually, the page does execute the entire page lifecycle on asynchronous postbacks.
However, the cause of the problem is that basically, once the script is registered on the page, it cannot be registered again. That is why using ScriptManager.RegisterStartupScript, ClientScript.RegisterStartupScript, and Page.RegisterStartupScript will only call the javascript on the initial load. It's like writing <script type="text/javascript" src="JScript.js" /><script type="text/javascript" src="JScript.js" /><script type="text/javascript" src="JScript.js" /> over and over in your document.
What you need to do, is clear the script element from the page, so that it can be readded upon asynchronous postbacks. Add the following on your page (changing the filename & path accordingly):
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(PageLoadedHandler);
function PageLoadedHandler(sender, args) {
var allScriptTags = document.getElementsByTagName("script");
for (i = allScriptTags.length; i >= 0; i--) {
if (allScriptTags[i] && allScriptTags[i].getAttribute("src")!=null && allScriptTags[i].getAttribute("src").indexOf("JScript.js") != -1) {
allScriptTags[i].parentNode.removeChild(allScriptTags[i]);
}
}
}
</script> Then place this in your Page_Load event (again changing the filename and path to what you need):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ScriptManager.RegisterStartupScript(Page, Page.GetType, "", "<script type='text/javascript' src='JScript.js' />", False)
End Sub
When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.
My latest ASP.NET AJAX blog entries.