Friday, April 29, 2011

Do you have to call RegisterClientScriptInclude in postback?

I need to register a javascript file from code-behind. I am interested to know whether this just needs to be called at the initial page load, or do I have to call it on each postback too ?

string clientUrl = ResolveClientUrl("~/Includes/global.js");
if (!Page.ClientScript.IsClientScriptIncludeRegistered(GetType(), "Global"))
    Page.ClientScript.RegisterClientScriptInclude(GetType(), "Global", clientUrl);
From stackoverflow
  • You're already checking the file if it's registered by the if clause. So register it in all postbacks. It doesn't matter.

    J.W. : but how about from some efficiency perspective, say, I don't want to include the check statement :-)
  • You should register it in all postbacks. Checking to see if it is registered already is not really necessary. It will only render one include with the name "Global".

0 comments:

Post a Comment