[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

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.
0
Jaymol
Asked:
Jaymol
  • 2
1 Solution
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now