I would recommend refactoring your code so that all of the common JS logic is stored in one place, and not in every UserControl. This will significantly reduce the size of your page.
You can pass the UserControl identifier to a common JS method to distinguish between UserControls.
To limit the scope of your UserControl variable, you can save some Key / Value structure to save your UserControl value - the key will be the UserControl client identifier, and the value you are interested in.
For example:
var UCFlags = new Object(); //set the flag for UserControl1: UCFlags["UC1"] = true; //set the flag for UserControl2: UCFlags["UC2"] = false;
To access them, you simply pass the ClientID UserControl identifier to the UCFlags array:
myFlag = UCFlags["UC1"];
On the server side, you can replace the constant string "UC1" or "UC2" with
<%= this.ClientID %>
like this:
myFlag = UCFlags["<%= this.ClientID %>"];
You can still use the syntax <% = this.ClientID%>, even if the bulk of the JS is in a separate file; just install
UCFlags["<%= this.ClientID %>"] = value;
before calling to embed the js file.
Ryan shripat
source share