Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:53:09+00:00 2026-06-12T03:53:09+00:00

I have a groups user control and javascript is defined inside the control. In

  • 0

I have a groups user control and javascript is defined inside the control. In a page, I have two such controls, which work independently. Rendered javascript is something similar to below:

//control 1
var Groups = (function () {
var obj = {};
obj.selectedid = 2;
return obj;
}());

//control 2
var Groups = (function () {
var obj = {};
obj.selectedid = 2; //it is different here, to keep it simple i just hardcoded as '2'
return obj;
}());

Could anyone please tell me how to access 1st Groups variable (control) on the Page. I thought something like Groups[0] would give me the result but it’s not.


Thanks for your replies. Much Appreciated. I am adding more information to be clear. User control contains dual listbox, user can add/remove values from list1 to list2. So I had encapsulated all this logic as below.

    var Groups = (function () {
    var obj = {};
    obj.selectedid = 2;

    //some local functions for internal operations such as
    function moveGroups(source, target){        
    }

     //there are public functions to initialize this control or to add groups as below 
    // Groups can be added from external page by calling  Groups.AddGroups(data);
    obj.AddGroups = function(data) {
           //refers to local variables and functions and adds data to listboxes
      };

    return obj;
    }());

Problem is I have two such Groups controls on the page. Group1 contains its own dual list and similarly Group2. Now, I would need to access AddGroups function of both objects work independently like Groups1.AddGroups(data) or Groups2.AddGroups(data) from the page.


I have worked out with below solution.

var Groups = Groups || []; //Check object already exists
Groups.push( 
//kept all the existing code here...
(function () {
    var obj = {};
    obj.selectedid = 2;

    //some local functions for internal operations such as
    function moveGroups(source, target){        
    }

     //there are public functions to initialize this control or to add groups as below 
    // Groups can be added from external page by calling  Groups.AddGroups(data);
    obj.AddGroups = function(data) {
           //refers to local variables and functions and adds data to listboxes
      };

    return obj;
    }())

);

Now in my page, I refer using:

Groups[0].AddAvailGroups();
Groups[1].AddAvailGroups();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:53:10+00:00Added an answer on June 12, 2026 at 3:53 am

    Two var Groups declarations define the same memory location.

    So your second statement

    //control 2
    var Groups = (function () {
    

    will overwrite value stored previously in Groups variable.

    If you want to access Groups as a collection you should do this explicitly:

    var Groups = []; // array/list;
    
    Groups.push( ... ); // control 1
    Groups.push( ... ); // control 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two instances of a user control on a page. Both have fields
I have a somewhat complex custom user control, created in C# .NET, which is
I have two web forms which are filled in by the user. They contain
I have a user control which contains a CustomValidator which is used according to
I have a query which gets me all groups the current user belongs to.
I often use the net user command to have a look at AD groups
I have two models, user and group. I also have a joining table groups_users.
Let's say I have two entities: Group and User. Every user can be member
I have two tables, locations and location groups CREATE TABLE locations ( location_id INT
Which version control system would you recommend for: single user looking for simple, easy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.