how to RegisterStartupScript JS.file

S

Stan Sainte-Rose

Hi,
I m working on a user control.
I need to use a Js file, I would like to know how to load the js file using
RegisterStartupScript command from the user control.
Also, if I load the same user controls several times in the same webpage, do
I have to check if the js file is still loaded ?

Stan
 
M

mortb

Maybe this would work:
RegisterStartupScript(someVariable,"<script
language='javascript'´src='yourInclude.js' />")

cheers,
mortb
 
S

Stan Sainte-Rose

Hi Mortb

I ve tried what you've said.. but it doesn't work for me.
Do not forget, I would like to use this within a user control.
Stan
 
T

Thomas Dodds

Be sure to send the startup script to the base page from your user control ... something like:

Dim strScript As New System.Text.StringBuilder()
Dim basePage As Page = Me.Page
Dim ScriptNameAsString as String = "SCRIPTNAME"

strScript.Append("<script language='javascript'´src='yourInclude.js' />")

If Not basePage.IsClientScriptBlockRegistered(ScriptNameAsString) Then basePage.RegisterClientScriptBlock(ScriptNameAsString, strScript.ToString)
 
S

Stan Sainte-Rose

Hi Thomas,

It sounds good.. I ve just a little problem.
I see the <script language='javascript' src='yourInclude.js'> comes inside
the <Form>
and my page has lost its design.
How could I get this tag outside the <form> tag ?

Thanks.

Stan

"Thomas Dodds" <[email protected]> a écrit dans le message de #[email protected]...
Be sure to send the startup script to the base page from your user control
.... something like:

Dim strScript As New System.Text.StringBuilder()
Dim basePage As Page = Me.Page
Dim ScriptNameAsString as String = "SCRIPTNAME"

strScript.Append("<script language='javascript'´src='yourInclude.js' />")

If Not basePage.IsClientScriptBlockRegistered(ScriptNameAsString) Then
basePage.RegisterClientScriptBlock(ScriptNameAsString, strScript.ToString)
 
T

Thomas Dodds

I think that is a function of the Page methods that register scripts - that is they are designed to place the text in the form tags ...

RegisterClientScriptBlock - The client-side script is emitted just after the opening tag of the Page object's <form runat= server> element.The script block is emitted as the object that renders the output is defined, so you must include both tags of the <script> element.

RegisterStartupScript - Similar to the RegisterClientScriptBlock method, this method emits the script just before the closing tag of the Page object's <form runat= server> element. The script block is emitted as the object that renders the page is defined, so you must include both tags of the <script> element.
 
S

Stan Sainte-Rose

Yes,

I use
If Not basePage.IsStartupScriptRegistered(ScriptNameAsString) Then
basePage.RegisterStartupScript(ScriptNameAsString, strScript.ToString)

But, when a function is called from my form it doesn't find the javascript
function :-(

If I use the your example, it works fine but as I said it breaks my design..



Stan





"Thomas Dodds" <[email protected]> a écrit dans le message de (e-mail address removed)...

I think that is a function of the Page methods that register scripts - that
is they are designed to place the text in the form tags ...

RegisterClientScriptBlock - The client-side script is emitted just after the
opening tag of the Page object's <form runat= server> element.The script
block is emitted as the object that renders the output is defined, so you
must include both tags of the <script> element.

RegisterStartupScript - Similar to the RegisterClientScriptBlock method,
this method emits the script just before the closing tag of the Page
object's <form runat= server> element. The script block is emitted as the
object that renders the page is defined, so you must include both tags of
the <script> element.
 
S

Stan Sainte-Rose

Ok, I ve found the problem.
It's strScript.Append("<script language='javascript'
src='myjsfile.js'></script>")
and not
strScript.Append("<script language='javascript' src='myjsfile.js'/>")

and it works fine with
If Not basePage.IsClientScriptBlockRegistered(ScriptNameAsString) Then
basePage.RegisterClientScriptBlock(ScriptNameAsString, strScript.ToString)



Thanks

Stan
 
T

Thomas Dodds

using RegisterStartupScript implies that you will be calling that script
from a client generated event... how are you using it?
 
S

Stan Sainte-Rose

yes..
I use something like this :
Saisie.Attributes("onblur") = "TypeChamps(this,'" & Row("TypeTest") & "');"
 
T

Thomas Dodds

I haven't ever used the <script ... /> syntax ... I merely copied something
from a previous post ... my apologies ...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top