A
Alex Maghen
I am building an ASP.NET UserControl. The UserControl will be making use of
one or two JavaScript functions. I want to assure that those functions will
be on the Page once and only once, but I don't want to have to remember to
insert the JavaScript on the page itself.
Instead, I want the UserControl to basically do this: Each time the
UserConrtol starts (PreRender? I'm not sure), I want it to check if a
JavaScript clock is loaded into the containing Page. If it is already there,
the control does nothing and just continues. If it's *not* there, it inserts
the JavaScript block itself.
This way, we're sure that the JavaScrip will be there if the control is
there, but we don't have to worry about it appearing on the page more than
once.
I think I should be using the
Page.ClientScript.IsClientScriptBlockRegistered()
function and also
Page.ClientScript.RegisterClientScriptInclude()
but I'm not sure how and I'm not sure where in the life-cycle of the
UserControl, this stuff can be tested and altered.
Any help, or even code-samples are much appreciated!
Alex
one or two JavaScript functions. I want to assure that those functions will
be on the Page once and only once, but I don't want to have to remember to
insert the JavaScript on the page itself.
Instead, I want the UserControl to basically do this: Each time the
UserConrtol starts (PreRender? I'm not sure), I want it to check if a
JavaScript clock is loaded into the containing Page. If it is already there,
the control does nothing and just continues. If it's *not* there, it inserts
the JavaScript block itself.
This way, we're sure that the JavaScrip will be there if the control is
there, but we don't have to worry about it appearing on the page more than
once.
I think I should be using the
Page.ClientScript.IsClientScriptBlockRegistered()
function and also
Page.ClientScript.RegisterClientScriptInclude()
but I'm not sure how and I'm not sure where in the life-cycle of the
UserControl, this stuff can be tested and altered.
Any help, or even code-samples are much appreciated!
Alex