Multiple user controls with core javascript

Hi.

I'm in the process of building a "web user control" for a C#/ASP.Net application.  There will be any number of these controls on the screen at one time, and each one has a bunch of javascript within itself to set visibility of divs at runtime, depending on user inputs.

I was just wondering if there's a nice way of having a core of javascript that all the controls use, without having it repeated throughout the resulting web page when it's rendered?

Thanks in advance.

John.
LVL 6
JaymolAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JaymolAuthor Commented:
It's okay - I've sorted it.

I'll post the solution on here shortly and accept it as a solution.

Thanks all the same.
0
JaymolAuthor Commented:
I added this code to the Render method of the web control....

      //  Parse the parent's child controls
      for (int i = 0; i < Parent.Controls.Count; i++)
      {
        //  If the parent's child control is the same type as this, we've found the first one.
        if (Parent.Controls[i].GetType() == this.GetType())
        {
          //  If the parent's child control has the same ID as this then this is the first one of this type.
          if (Parent.Controls[i].ID == this.ID)
          {
            //  Add javascript here
          }
          break;
        }
      }


Now, I can have one instance of a bunch of javascript functions that all the controls of the same type can call.  I just pass this.ID around as a controlID within the javascript in order to identify which control is making the call.

Hope this proves useful.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.