473,756 Members | 5,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Control Javascript

I'm trying to have a javascript file included with my usercontrol, but
when the page loads it says that none of my JS methods are there.
What are the steps that I need to take to get a javascript file to go
with the user control so that I don't have to load the script onto the
page that is calling the control?
Jan 17 '08 #1
3 4189
Try something like this:

In your AssemblyInfo.cs file, place the following:

[assembly: System.Web.UI.W ebResource("Ass emblyName.filep ath.FileName.js ",
"text/javascript")]

where AssemblyName is, for instance, MyNamespace.dll , so "MyNamespac e", then
each folder nested within your assembly, e.g. in my project I have a folder
called "scripts", so filepath above would be "scripts", the result would be
"MyNamespace.sc ripts.MyFile.js ".

Ensure in the file properties within Solution Explorer in VS that the Build
Type is "Embedded Resource" for the script file itself.

Finally, override the OnPreRender event in your control, add the following
(if you are going to be using a ScriptManager control/AJAX, otherwise use
Page.ClientScri pt... where you see ScriptManager:

// Register JavaScript
string jsPath = Page.ClientScri pt.GetWebResour ceUrl(this.GetT ype(),
"Retina.Web.UI. Controls.Floati ngMenu.Floating Menu.js");
ScriptManager sm = ScriptManager.G etCurrent(this. Page);
ScriptReference sr = new ScriptReference (jsPath);
if (!sm.Scripts.Co ntains(sr))
sm.Scripts.Add( sr);
Hope that helps. Let me know if you have any questions or if anyone has a
more efficient way of doing this by all means...

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"cfps.Christian " wrote:
I'm trying to have a javascript file included with my usercontrol, but
when the page loads it says that none of my JS methods are there.
What are the steps that I need to take to get a javascript file to go
with the user control so that I don't have to load the script onto the
page that is calling the control?
Jan 17 '08 #2
Well the first part of my problem is that I don't have the
AssemblyInfo.cs since I unfortunately have to code this in VB. Even
then I'm not sure how to make it appear because I know there is an
assembly info hiding somewhere in my project.
Jan 18 '08 #3
You can't do it in Web Site project. I've been trying to solve the same
problem, but it seems you have to create separate class library with
resources embedded as you said and then merged with ILMerge/aspnet_merge.
Haven't tested it yet.

Regards
--
Milosz
"Chad Scharf" wrote:
Try something like this:

In your AssemblyInfo.cs file, place the following:

[assembly: System.Web.UI.W ebResource("Ass emblyName.filep ath.FileName.js ",
"text/javascript")]

where AssemblyName is, for instance, MyNamespace.dll , so "MyNamespac e", then
each folder nested within your assembly, e.g. in my project I have a folder
called "scripts", so filepath above would be "scripts", the result would be
"MyNamespace.sc ripts.MyFile.js ".

Ensure in the file properties within Solution Explorer in VS that the Build
Type is "Embedded Resource" for the script file itself.

Finally, override the OnPreRender event in your control, add the following
(if you are going to be using a ScriptManager control/AJAX, otherwise use
Page.ClientScri pt... where you see ScriptManager:

// Register JavaScript
string jsPath = Page.ClientScri pt.GetWebResour ceUrl(this.GetT ype(),
"Retina.Web.UI. Controls.Floati ngMenu.Floating Menu.js");
ScriptManager sm = ScriptManager.G etCurrent(this. Page);
ScriptReference sr = new ScriptReference (jsPath);
if (!sm.Scripts.Co ntains(sr))
sm.Scripts.Add( sr);
Hope that helps. Let me know if you have any questions or if anyone has a
more efficient way of doing this by all means...

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"cfps.Christian " wrote:
I'm trying to have a javascript file included with my usercontrol, but
when the page loads it says that none of my JS methods are there.
What are the steps that I need to take to get a javascript file to go
with the user control so that I don't have to load the script onto the
page that is calling the control?
Jan 18 '08 #4

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

Similar topics

2
1867
by: Jakub Gutkowski | last post by:
Hi, Dose anybody knows how to call JavaScript function in C# Windows User Control? I use Windows User Control as smth like ActiveX, 'coz I need to call
4
4291
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage I know I need to call a function that will save data but I'm not sure exactly when to call this function. I've tried two ways and both seem to have 'gotcha's':
0
1004
by: Jakub Gutkowski | last post by:
Hi, Dose anybody knows how to call JavaScript function in C# Windows User Control? I use Windows User Control as smth like ActiveX, 'coz I need to call functions from my User Control from JavaScript - same as You can do it with ActiveX (just put objectId dot and name of function). But know, one of my functions in User Control need do call a javascript function, which is placed on aspx site.
3
2080
by: Ant | last post by:
I'm building a Web user control that has several public functions. Can I fire them from the client side? for example Javascript and an HTML button
1
5407
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for that), the popup window will have also a text box and a button. when the User click on the button the value on the textbox will be send back to the textbox on My_WUC. I hope I was clear off what I want to do. I've been searching for some ideas...
0
2491
by: jonathan.beckett | last post by:
I have been working on a client project recently that is using winforms ..NET user controls within web pages in Internet Explorer, and need to find out how to make the user control communicate back to the webpage (typically to tell it that it has finished doing something). I started digging around and found out that I needed to implement a COM interface for the .NET user control, and pick up the events from that in Javascript on the...
1
2390
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...
1
501
by: olivier | last post by:
Hi, I want to use javascript (ajax) in User Control but to call the object is difficult. If my user control is called MyControl. To use the object in javascript, i make, Ex: document.GetElementId("MyControl_textbox").value
3
2518
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a user control which I use on all my pages. The control is situated on the top of my page (sits on my master page). For some long pages the user has to scroll back up to the top of the page to select an option from my user control. Can I make this user control floatable so that as the user scrolls down the page the user control moves down also?
4
4237
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
9462
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
9287
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
10046
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
9886
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...
0
9722
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
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...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6542
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
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.