473,651 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript file won't work with RegisterClientS cript

Hello,

I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all
the updates. I have an aspx page with javascript that works fine until I
try to separate the script into a .js file. I've found that only the script
that is called from events set in the aspx.cs file don't work. I eliminated
all script except two functions. One is used with the .cs file and the
other one is not.

First, here's the functino used with the .cs file:
if (!this.IsPostBa ck)
{

btnFirst.OnClie ntClick = "return btnFirst_Click( )";

}
.... the javascript function is...
function btnFirst_Click( )

{

alert("This is btnFirst_Click" ):

return false;

}

Now the second javascript function is only

function ShowAlert()
{
alert("This is ShowAlert");
return false;
}

This function is called from another button - button1 - from the
OnClientClick event which I set in the property page..

When I have all the javascript in the aspx page, it all wokrs, but when I
move it to a .js file, the first function doesn't work, but the second one
does.

I don't want to add all my javascript in rhe .cs file because that would
expose all my code - that's why I'm teying to put it in a .js file.

How can I make all the code work using both methods?
Thanks.
--
Matthew.Wells
Ma***********@F irstByte.net
Jun 27 '08 #1
0 879

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

Similar topics

2
2840
by: Brian Bischof | last post by:
I'm trying to add javascript to a page so that it gets executed when the page opens. I also need to do this during runtime b/c the javascript will change each time. In MSDN I saw that you can make the <Body> tag a server side object and then add an attribute to it. Example: <Body Id="Body1" runat="server"> in VB.NET Body1.Attributes.Add(...)
7
22021
by: walter | last post by:
Here is my case : I create a user control which contains One checkbox control to enable/disable the other two textbox control. I'm using server control instead of HTML control, and I don't want to post back to server to do the disable. The problem is I there is no easy way for me to find the ID in the javascript since the ID or name are all prefixed with parent name. Even worse, this control could be wrapped with another user control...
3
1274
by: Zdenko Rupcic | last post by:
I want to add a javascript which would execute only if certain requirements are met. Example: If user isn't logged in, a message box would pop up, telling the user he has to log in, but if the user is already logged in, there would be no message. In classical asp, I would do it like this: <body<% IF LEN(Session("username"))=0 THEN Response.Write " onLoad=""alert('You need to log in for more info!')""" %>>
11
3636
by: Boris Twila | last post by:
i need a tutorial thanks
3
3015
by: First Last | last post by:
Hi, Newbie question: Why use Page.ClientScript.RegisterClientScript* when we can just make a .js file and include a reference to it in the page? (i.e. <script src="myscript.js" type="text/javascript"></script>) Is it because RegisterClientScript* enables us to reference ASP.NET objects within the .js? Thx, Hank
2
2212
by: baburk | last post by:
Hi all, when I call the javascript method from code behind file of the same page it works fine. ScriptManager.RegisterClientScriptBlock(this, Page.GetType(), "Scroll", "ScrollToPosition();", true); But when i put the JavaScript method in the masterpage, there the problem occurs.
2
2740
by: Matthew Wells | last post by:
Hello. I'm reposting this because my prioe post's subject line was incorrect. I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all the updates. I have an aspx page with javascript that works fine until I try to separate the script into a .js file. I've found that only the script that is called from events set in the aspx.cs file don't work. I eliminated all script except two functions. One is used with the .cs file...
9
2213
by: Matthew Wells | last post by:
OK, I've narrowed down the problem. This works when in the aspx page <script type="text/javascript" > function btnFirst_Click() { alert("Hello"); alert(document.getElementById("<%=LBFacilities.ClientID%>").options.length); return false; } </script>
1
4080
by: greatvishal | last post by:
Hi, I have a page where I am trying to render a pdf file using response.contenttype = "application/pdf". when the page has rendered, I need to launch a javascript command to launch the window's print dialog box which is usually done using window.print() The issue is because of contenttype not being html, page wouldn't fire the javascript function so can't auto launch the priting dialog. Here is the C# code, which i using to display pdf...
0
8352
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
8697
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
8465
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
7297
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
6158
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
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
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
2
1587
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.