Master Pages using JavaScript.js file

J

jeff3048

Hi,

I want to incorporate a JavaScript routine (found on the internet) in my
page that will restore the scrollbar position of a div tag on postback. I am
using master pages which complicates things and also want to reference the
script via a ".js" file. Below is the code I have come-up with but it
doesn't work (I get a blank screen). The script is located in the project
folder in the JavaScript folder. Any ideas?

Thanks,
Jeff


Page.RegisterClientScriptBlock("MyScript", "<script
language=javascript src='JavaScript/sscroller.js'>");
 
N

Nicholas Paldino [.NET/C# MVP]

Jeff,

Instead of using the RegisterClientScriptBlock (which is tagged as
obsolete) why not just use the RegisterClientScriptInclude method on the
ClientScriptManager class? You don't need to write the script, you just
would have to include the url of the script to include.

Also, I notice you are using a relative URL. If this is a master page,
and it is going to be used for pages across different directories, then the
URL is constantly going to change. You might want to make the URL relative
to the root, using "/JavaScript/sscroller.js" (note the initial slash).
 

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

Top