473,586 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you centrally store and include reusable javascript functions into .aspx pages?

Hi,

I would like to create a central storage place for javascript
functions that I can then access from any of my asp.net projects.

An example of what I need it for is as follows:

I have a class library that contains a function I use all the time (to
create a link around some text). That function in turn calls a
javascript function. Usually I would have put the javascript on the
page by using:

If (Not IsClientScriptB lockRegistered( "clientScript") ) Then
RegisterClientS criptBlock("cli entScript", strJava)
End If

(where strJava = my javascript function etc)

Because IsClientScriptB lockRegistered is part of the Page class, I
can't do this in my class library.

The other option I thought of was including a javascript file as an
include on my .aspx page, but I would want the .js page to use in many
different projects, not just in one project.

Does anyone have any ideas as to what is the best way to store
reusuable javascript functions and how to access them?

Many thanks,

Nikki
Nov 17 '05 #1
3 3919
ni*****@talk21. com (Nikki) wrote in
news:8d******** *************** ***@posting.goo gle.com:
Hi,

I would like to create a central storage place for javascript
functions that I can then access from any of my asp.net
projects.

An example of what I need it for is as follows:

I have a class library that contains a function I use all the
time (to create a link around some text). That function in turn
calls a javascript function. Usually I would have put the
javascript on the page by using:

If (Not IsClientScriptB lockRegistered( "clientScript") ) Then
RegisterClientS criptBlock("cli entScript", strJava)
End If

(where strJava = my javascript function etc)

Because IsClientScriptB lockRegistered is part of the Page class,
I can't do this in my class library.


Nikki,

Yes you can. Create a method that takes a System.Web.UI.P age as a
parameter. Here's an example in C#:

public class JavaScriptHelpe rs
{
public static void RegisterJavaScr iptSource(
System.Web.UI.P age page,
string key,
string code)
{
if (!page.IsClient ScriptBlockRegi stered(key))
page.RegisterCl ientScriptBlock (key, code);
}
}
From your page, you can call this method like this:

// Use "Me" instead of "this" as the first parameter
// in VB.NET.
JavaScriptHelpe rs.RegisterJava ScriptSource(th is,
"clientScri pt", strJava);
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #2
Hi Chris,

Thanks for your prompt reply!

I have tried passing in the Page to the function as follows, but it
didn't like it.

Public Class Detail

Function MapText(ByVal PC As String, ByVal Page As System.Web.UI.P age)
As String

...

End Function
End Class

It says that System.Web.UI.P age is not defined. I think this is what you
meant in your reply.

Many thanks in advance for your help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3
Of course! Many thanks Chris.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
2250
by: Matt Kruse | last post by:
Since this topic has come up several times in other threads, I thought I'd make a separate thread and gather opinions from (hopefully) a more varied range of newsgroup participants. What are your thoughts on the development and use of generalized, reusable javascript libraries? Discussion points: 1) Is the overhead of a 25k (for...
6
1251
by: Jamie | last post by:
Hi there, I have a bit of java script which I would like to include in all of my html pages. Is there an easy way to include it with a reference or something. I don't want to have to copy and paste the code to the top of each page as if I then change the code I have to go through all pages to change it.
21
2928
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not...
7
2228
by: Matt Jensen | last post by:
Howdy I want to simulate with .Net what I used to do with classic ASP where you would have a series of include files with utility functions that you would include when you needed them. I read some article about creating a utility class, but it gave no details, and I'm not sure what to do. Do I create a .cs file and then just include it?...
2
254
by: Ramon Rocha | last post by:
Dear friends, How do I do to includes files .aspx in ASP.NET pages <script></script>? Ex: config.aspx ------------ Dim strLanguage as string strLanguage = "en-US"
14
2332
by: Julesh | last post by:
Hello, I am new to ASP and am trying to make some changes to some ASP 3.0 code I have inherited. I have a number of ASP pages with VBS as the base language, on each of these pages I have successfully included a piece of VBS code that produces output in a table cell by using: <!--#include file="showAnswers.inc" -->
1
1646
by: Nemisis | last post by:
Hi everyone, In a asp.net web application, where is the best way/best practice way to store external javascript files that i want to reference in pages/ web controls etc? None, of my scripts contain passwords, they are just useful scripts, that i use in multiple controls.
1
1249
by: mtek | last post by:
Does Javascript support include files? I have some functions that I need in 4 pages with Javascript. Can I somehow include that data by using a general include file? All of the Javascript is not the same, just some functions. So, I really have only one set to <SCRIPT>.....</ SCRIPT>. Much of that code is unique to the page, but some...
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.