473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Troubles using javascript file as a webresource

4
I have a web user control with a button on it and i want to hook a javascript function to this button.

This is my web user control code:

Expand|Select|Wrap|Line Numbers
  1. <Assembly: WebResource("jstest.js", "text/javascript")> 
  2. Partial Class WebUserControl
  3.     Inherits System.Web.UI.UserControl
  4.  
  5.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As    System.EventArgs) Handles Me.Load
  6.  
  7.         ' Define the resource name and type.
  8.         Dim rsname As String = "jstest.js"
  9.         Dim rstype As Type = Me.GetType()
  10.         ' Get a ClientScriptManager reference from the Page class.
  11.         Dim cs As ClientScriptManager = Page.ClientScript
  12.         '  Get the web resource url.
  13.         Dim ResourceURL As String = cs.GetWebResourceUrl(rstype, rsname)
  14.         cs.RegisterClientScriptInclude(rstype, "myscript", ResourceURL)
  15.         ' Register the client resource with the page.
  16.         cs.RegisterClientScriptResource(rstype, rsname)
  17.         ' Hook js function to the button.
  18.         Button1.Attributes.Add("onClick", "javascript:return test();")
  19.  
  20.     End Sub
  21. End Class 
This is the jstest.js content:

Expand|Select|Wrap|Line Numbers
  1.  function test()
  2. {
  3.    alert("Hello World");
  4.    return(false);
This is not working. Internet explorer just indicates 'Error on the page' on the status bar and there is just this message on the detail error information: 'Object expected'... Can any body help me to make this work? am i missing something?.

I need it to be this way cause i have several javascript files with functios that i need to hook to some other controls in my web user components.

Hope anybody can help me with this...
Thanks in advance.
Aug 28 '07 #1
3 3601
nateraaaa
663 Expert 512MB
I have a web user control with a button on it and i want to hook a javascript function to this button.

This is my web user control code:

Expand|Select|Wrap|Line Numbers
  1. <Assembly: WebResource("jstest.js", "text/javascript")> 
  2. Partial Class WebUserControl
  3.     Inherits System.Web.UI.UserControl
  4.  
  5.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As    System.EventArgs) Handles Me.Load
  6.  
  7.         ' Define the resource name and type.
  8.         Dim rsname As String = "jstest.js"
  9.         Dim rstype As Type = Me.GetType()
  10.         ' Get a ClientScriptManager reference from the Page class.
  11.         Dim cs As ClientScriptManager = Page.ClientScript
  12.         '  Get the web resource url.
  13.         Dim ResourceURL As String = cs.GetWebResourceUrl(rstype, rsname)
  14.         cs.RegisterClientScriptInclude(rstype, "myscript", ResourceURL)
  15.         ' Register the client resource with the page.
  16.         cs.RegisterClientScriptResource(rstype, rsname)
  17.         ' Hook js function to the button.
  18.         Button1.Attributes.Add("onClick", "javascript:return test();")
  19.  
  20.     End Sub
  21. End Class 
This is the jstest.js content:

Expand|Select|Wrap|Line Numbers
  1.  function test()
  2. {
  3.    alert("Hello World");
  4.    return(false);
This is not working. Internet explorer just indicates 'Error on the page' on the status bar and there is just this message on the detail error information: 'Object expected'... Can any body help me to make this work? am i missing something?.

I need it to be this way cause i have several javascript files with functios that i need to hook to some other controls in my web user components.

Hope anybody can help me with this...
Thanks in advance.
In your html code for the button do you have a runat="server" tag?

Nathan
Aug 28 '07 #2
Lucas
4
In your html code for the button do you have a runat="server" tag?

Nathan
Yes i do. And to lengthen my message to at least 20 characters this is my web user control client side code showing the runat="server" tag:

Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.ascx.vb" Inherits="WebUserControl" %>
  2. <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 26px; position: absolute;
  3.     top: 26px" Width="178px">Press Button</asp:TextBox>
  4. <asp:Button ID="Button1" runat="server" Style="z-index: 102; left: 143px; position: absolute;
  5.     top: 51px" Text="Click" Width="52px" />
Any idea?...
Aug 28 '07 #3
Lucas
4
I found a solution to my problem. It is not exactly what i wanted but it's working. Instead of using the javascript file as an embedded resource, this aproach uses it as a linked resource. For whoeverneedingsomethinglikethis's sake here is the code to add javascript to a web user control as mentionated:

Web control class code:

Expand|Select|Wrap|Line Numbers
  1. Partial Class WebUserControl
  2.     Inherits System.Web.UI.UserControl
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.  
  6.         ' Define the resource name and type.
  7.         Dim rsname As String = "jstest.js"
  8.         Dim rstype As Type = GetType(WebUserControl)
  9.         ' Get a ClientScriptManager reference from the Page class.
  10.         Dim cs As ClientScriptManager = Page.ClientScript
  11.         cs.RegisterClientScriptInclude(rstype, "myscript", rsname)
  12.         ' Hook js function to a button.
  13.         Button1.Attributes.Add("onClick", "javascript:return test();")
  14.  
  15.     End Sub
Lucas.
Aug 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Rich | last post by:
I am converting my enterprise solution from VS 2003 (.NET v1.1.4322) to VS 2005 (.NET v2.0.50727). The entire solution uses serveral technologies - Windows Server 2003 (AD, SQL Server 2000, IIS,...
3
by: Dav | last post by:
Hi, I moved over client side javascript code from an asp.net 1.1 project to an asp.net 2.0 project. When I view the web page, I get all these "is null or is not object" javascript errors. Is...
4
by: Greg | last post by:
I'm guessing the problem I'm having has something to do with Master Pages or DetailsView because the exact same code works fine on a page without a Master Page and DetailsView controls. The...
1
by: AndiSmith | last post by:
Hi guys, I wondered if anyone could help me with this problem, or even shed some light on the direction I need to take to resolve it? I'm using .NET 2.0 (C# flavor) to build a large user-based...
1
by: John | last post by:
Is there an automatic way of filling forms that have been generated using javascript? I tried to use python+mechanize but am having trouble with javascript forms. This is the way the form is...
2
by: Håkan | last post by:
I have a problem with WebResource.axd Most of the requests to this site work just fine but every now and then I recive described below: Date: 2007-02-13 15:20 ...
3
by: fnustle | last post by:
I've embedded a flash file into an assembly: But when I try to reference it on a web page: <object codebase="http://download.macromedia.com/pub/shockwave/ cabs/flash/swflash.cab"...
0
by: =?Utf-8?B?TG93bGFuZGVy?= | last post by:
Hello, I've built a web application that uses client script callbacks. It is used on a large network with a large variety of user OSes and IE versions. It was tested on IE 6 on different setups...
2
by: =?Utf-8?B?UGFi?= | last post by:
I am developing the web controls and try to include all client files: scripts, styles, etc in an assembly as resource common way like: , and use ClientScriptManager class. I have faced a problem...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.