Home All Groups Group Topic Archive Search About

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

Author
9 Feb 2009 3:52 PM
MGKR
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

Author
9 Feb 2009 11:37 PM
Nathan Sokalski
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
njsokal***@hotmail.com
http://www.nathansokalski.com/

Show quoteHide quote
"MGKR" <no-reply@spam.com> wrote in message
news:%23I5UC4siJHA.1168@TK2MSFTNGP05.phx.gbl...
> 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
>
Author
11 Feb 2009 9:15 AM
Patrice
See Page.ClientScript
(http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx)

It allows to manage client side scripts and in particular to register a
script once (using
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx
or other registration checking methods)...

If this is not a script registration problem please be a bit more specific
about the exact problem...

--
Patrice

"MGKR" <no-reply@spam.com> a écrit dans le message de groupe de discussion :
#I5UC4siJHA.1***@TK2MSFTNGP05.phx.gbl...
Show quoteHide quote
> 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
>