Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPIJavascript call in a module.Urgent.Javascript call in a module.Urgent.
Previous
 
Next
New Post
12/31/2008 10:18 AM
 

Hi,

I have a module in which i am adding a javascript function. I am then adding this module in a page more than once. The javascript function is getting rendered for each module and only the last script is called.

say, i place MODULE1(a dnn compiled module) in a page twice. Then the javascript function will be rendered twice for that page. But when the functionis called, it always calls the last function rendered for that page.

So i am having a problem with separation of script for a module that is placed multiple times on a page.

Please suggest me a solution.

Please find the code attached.

function

CheckItem(checkBoxList) {var options = checkBoxList.getElementsByTagName('input');var arrayOfCheckBoxLabels = checkBoxList.getElementsByTagName("label");var hiddenFilterString = document.getElementById('<%=hiddenCheckBoxListValues.ClientID%>');var hdnFieldColumnName = document.getElementById('<%=hiddenColumnName.ClientID%>');var tempStringBuild = "";//document.getElementById("hdnSutunlar").value="";

 

 

 

 

for (i = 0; i < options.length; i++) {var opt = options[i];if (opt.checked) {// arrayOfCheckBoxLabels[i].innerText);

 

tempStringBuild = tempStringBuild +

 

if (tempStringBuild.match(arrayOfCheckBoxLabels[i].innerText) != arrayOfCheckBoxLabels[i].innerText) {"'" + arrayOfCheckBoxLabels[i].innerText + "'" + ',';// r);

}

}

}

tempStringBuild = rtrim(tempStringBuild,

tempStringBuild = hdnFieldColumnName.value +

 

",");" in (" + tempStringBuild + ")";// empStringBuild);

hiddenFilterString.value = tempStringBuild;

 

// nHidden);

 

// hiddenFilterString.value);

 

//btnHidden.click();

}

 

 

 

 

 

 

 
New Post
12/31/2008 5:21 PM
 

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.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
1/4/2009 1:25 PM
 

Perhaps this video I put together will help.


 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPIJavascript call in a module.Urgent.Javascript call in a module.Urgent.


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out