How to prevent JavaScript conflict in custom server control (when added more than once to a page)

Discussion in 'ASP .Net Web Controls' started by MGKR, Feb 9, 2009.

  1. MGKR

    MGKR Guest

    How do you go about solving this?

    Ie. unless the JavaScript, included with the server control (which might
    reference ID's in the generated HTML), somehow knows which control it
    belongs to - A problem will occur if two or more of the same control are
    included on the same page.

    It's no problem ensuring that unique ID's are generated for each use of a
    particular control - But then what with the JavaScript referencing those
    ID's?

    Are there any general Pattern&Practice for solving this?

    I've searched high and low on the net without much luck.

    Would very much appriciate some pointers to some links that dig into this
    subject..


    /MGKR
    MGKR, Feb 9, 2009
    #1
    1. Advertising

  2. Well, you can always generate a separate function for each instance of the
    control and give the function a name like <CONTROLID>_myfunction(). However,
    if the JavaScript is being used with instances of the same control there is
    usually a way to write it so that the same JavaScript can be used for all
    instances, often by passing a few extra parameters. If you tell us exactly
    what your control's JavaScript is supposed to do we may be able to make a
    few suggestions. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "MGKR" <> wrote in message
    news:%...
    > How do you go about solving this?
    >
    > Ie. unless the JavaScript, included with the server control (which might
    > reference ID's in the generated HTML), somehow knows which control it
    > belongs to - A problem will occur if two or more of the same control are
    > included on the same page.
    >
    > It's no problem ensuring that unique ID's are generated for each use of a
    > particular control - But then what with the JavaScript referencing those
    > ID's?
    >
    > Are there any general Pattern&Practice for solving this?
    >
    > I've searched high and low on the net without much luck.
    >
    > Would very much appriciate some pointers to some links that dig into this
    > subject..
    >
    >
    > /MGKR
    >
    Nathan Sokalski, Feb 9, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    427
  2. keithb
    Replies:
    4
    Views:
    741
    Patrick.O.Ige
    Apr 8, 2006
  3. Superman
    Replies:
    0
    Views:
    285
    Superman
    Feb 27, 2007
  4. lds
    Replies:
    0
    Views:
    381
  5. Gancy
    Replies:
    4
    Views:
    176
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page