473,769 Members | 5,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple javascript for user controls

Hi,
I have a usercontrol which includes a small piece of Javascript built up
as a string in <scripttags and put onto a web page when an instance of the
User Control is created. The Javascript does some client side checking of
User Input.

If I use multiple instances of the same user control on a page, the same
block of Javascript is repeatedly written to the page (once for each instance
of the user control). Although the user controls still work, it creates a
bigger page to download from the server.

Is ther any way of just writing the Javascript the once to the page? or is
there a better way of getting the Javascript written. (I wanted to keep the
Javascript integral to the user control so that it was independent).

Many thanks,

Pete
Oct 12 '06 #1
1 2391
Hi Italian Pete,

You can use an ASP.NET feature to register the scripts. You uniquely
identify them with keys.

Here is some example code.

string key = "script1";
string url = "scripts/script1.js";

if (!Page.ClientSc ript.IsClientSc riptIncludeRegi stered(key))
{
Page.ClientScri pt.RegisterClie ntScriptInclude (key, url);
}

That will ensure it is only included once per key.

You can also build an assembly which embeds the scripts you are using
to make it easy to deploy them with your website.

I created an assembly with a control to manage the scripts here...

http://svn.offwhite.net/svn/SmallSha...Scripts/trunk/

You can browse the code to see what I did there. It is a Subversion
repository so you could use TortoiseSVN to pull down the whole project
and work use it.

Brennan Stehling
http://brennan.offwhite.net/blog/

Italian Pete wrote:
Hi,
I have a usercontrol which includes a small piece of Javascript built up
as a string in <scripttags and put onto a web page when an instance of the
User Control is created. The Javascript does some client side checking of
User Input.

If I use multiple instances of the same user control on a page, the same
block of Javascript is repeatedly written to the page (once for each instance
of the user control). Although the user controls still work, it creates a
bigger page to download from the server.

Is ther any way of just writing the Javascript the once to the page? or is
there a better way of getting the Javascript written. (I wanted to keep the
Javascript integral to the user control so that it was independent).

Many thanks,

Pete
Oct 12 '06 #2

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

Similar topics

2
1935
by: Sundar | last post by:
Hi, I am working on ASP.Net. My requirement is that I want to Upload Multiple Files to the Server. I need to have ONLY ONE FILE UPLOAD CONTROL in my page. I SHOULD NOT SUBMIT THE PAGE FOR EACH AND EVERY DOCUMENT browsed. I am having a File Upload HTML Control and an Add Button on my page. The user will browse for the document to be uploaded and then click on that Add button. I then add the
3
2415
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the list boxes'). Users can add and remove items from the list boxes. When the users are adding and removing items, the list boxes are single
1
1777
by: .Net Newbie | last post by:
I am relatively new to .Net and have been coding an intranet site for my employer for a couple of months. I am currently stuck coding in a text-editor called EditPlus without access to the VS.Net IDE, and coding pages with the script directly in each page (not using the codebehind method) as most of my learning material has demonstrated. I started with the IBuySpy Portal (SDK version not VS Version) as my base portal and have coded...
4
5037
by: Diane Selby | last post by:
Hi- I am developing an ASP.NET application that can take a few seconds to process the request from the user. We are looking for a client-side solution that will prevent users from resubmitting the page multiple time in their irrational impatience. There are a few posts on this group which suggest that we use JavaScript hooked up to the page's OnSubmit event to catch mulitple submissions. See postings by Craig Deelsnyder et alia.
0
1237
by: .Net Newbie | last post by:
I am relatively new to .Net and have been coding an intranet site for my employer for a couple of months. I am currently stuck coding in a text-editor called EditPlus without access to the VS.Net IDE, and coding pages with the script directly in each page (not using the codebehind method) as most of my learning material has demonstrated. I started with the IBuySpy Portal (SDK version not VS Version) as my base portal and have coded...
6
2408
by: Shashi | last post by:
I have developed ASP.Net application using .Net 1.1 Framework. When the user clicks image file through Java script I am using my search window as below. QueryString = "frmMySearchWebForm.aspx?DOBDate=" + txtDOBDt popUp =window.open(QueryString,null, "height=50,width=80,status=no,left =0,top =0,toolbar=no,menubar=no,location=no,scrollbars =yes"); When the user picks a certain customer in the frmMySearchWebForm I am
3
2793
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +201 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +263
1
1898
by: Italian Pete | last post by:
Hi, I have a usercontrol which includes a small piece of Javascript built up as a string in <scripttags and put onto a web page when an instance of the User Control is created. The Javascript does some client side checking of User Input. If I use multiple instances of the same user control on a page, the same block of Javascript is repeatedly written to the page (once for each instance of the user control). Although the user controls...
4
4239
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user control.. but if i add javascript in page in which i am adding user control then that javascript is executed properly. i tested by displaying alert message in javascript. can anyone tell
0
9589
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10048
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.