Rather than including the source for the js function in a script block in your control's .ascx markup, I would suggest using RegisterClientScriptBlock with the same type and/or key to dynamically inject the client script code for you. That way, there will be only one instance of the client script rendered on the page. The RegisterClientScriptBlock method is available to you through three different namespaces:
In the following, myScript represents a string containing the client script code.
1. Using the ClientScriptManager object:
If Not Page.ClientScript.IsClientScriptRegistered (GetType(Me), "myKey") Then
Page.ClientScript.RegisterClientScriptBlock (Page, GetType(Me), "myKey", myScript, True) ' Last parameter = True wraps with < script > ... < /script >
End If
2. Using the AJAX ScriptManager:
ScriptManager.RegisterClientScriptBlock (Page, GetType(Me), "myKey", myScript, True)
3. Using the DNN ClientAPI:
If Not DotNetNuke.UI.Utilities.ClientAPI.IsClientScriptBlockRegistered("myKey") Then
DotNetNuke.UI.Utilities.ClientAPI.RegisterClientScriptBlock(Page, "myKey", myScript)
End If
#1 is the most general method.
#2 should be used when there is an AJAX ScriptManager on the page AND the control for which the client script is being renderes is located within an AJAX UpdatePanel as this method will work with partial page rendering. I find myself using this method most often.
#3 is the DNN way (pre-AJAX) and simply calls the first method. I don't use this one since you have to include our own < script > . . . < /script > tags.
Now that there will be only one copy of the js code on the page and since the code will not be part of your .ascx file, you will need to pass the ClientIDs of any elements referenced in the code into the CheckItem function when it is being called.