Content Handler

How can I call a Javascript function on loading the body of a content page? Since I cannot use the body loading of my main page body onloadin this.

+3
source share
4 answers

If you are using ASP.NET Ajax, you can add a load handler to your content page:

Sys.Application.add_load(contentPageLoadHandler);

function contentPageLoadHandler() {
    // do stuff
}

Using this approach, each page of content or even each control can configure its own load handler. See this page for more details .


Alternatively, if you use jQuery, you can achieve the same using this approach (on your content page):

$(document).ready(function() {
  // do stuff
});

. .

+2

StartupScipt

Page.RegisterStartupScript("name", script);
+1

Successful attempt with window.onload:

window.onload=function(){
 foo();
}
+1
source

It seems that you have already dealt with the problem before, just for googlers, in fact you can use onload from your main page, con 'is that you will need to specify the same javascript function name to call on each page, maybe to be empty in some cases ...

+1
source

Source: https://habr.com/ru/post/1702914/


All Articles