Why is RegisterClientScriptInclude causing multiple page loads?

278 views Asked by At

After much banging of the head and manual line-by-line code removal, I have figured out that a RegisterClientScriptInclude call inside an ASCX web control is causing multiple page_load events to fire. This only happens when the ASCX is included on some pages, but not others.

Removing this line of code causes the double-postback to stop:

Page.ClientScript.RegisterClientScriptInclude(
    Page.GetType(), 
    "[SCRIPTNAME]", 
    "[SCRIPTFILE].js")

I also tried this without including Page.GetType(), to no avail.

1

There are 1 answers

2
Nathan Prather On

That line of code shouldn't be causing multiple page loads... There's probably something else going on... I would turn on Tracing at the page level and throw some Trace.Warn statements in to see what's going on...

But I'm not a big fan of the Page.ClientScript.RegisterClientScriptInclude() method and find that it's usually easier just to include the .js file in the parent aspx page... It's a very mild performance hit if that .js file isn't needed on a particular page...