Click here to Skip to main content
15,847,583 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my solution i'm having a
Quote:
Scripts/Functionalities/JSFunctions.js


Now in my ASPX page i need to use the function name "ShowAlert()" inside the "JSFunctions.js"


I just drag and drop the URL of JS file inside my ASPX page. But while i call like

<asp:Button ID="butSavetop" runat="server" Text="Save" OnClientclick="ShowAlert();"/>


It Shows error like "Object Expected"

I'm using VS2010. Am i need to change any property of my JS file ??
Its working fine while i using the function "ShowAlert();" inside the same ASPX page.

Now its working fine for HTML button. It cause trouble for asp button.
Posted
Updated 10-Jul-12 6:34am
v3

write code in onclientclick event

ASP.NET
<asp:Button ID="butSavetoprunat="server" Text="Save" OnClientClick="ShowAlert();"/>
 
Share this answer
 
v2
Comments
J.Karthick 10-Jul-12 9:04am    
Yes, i tried it
but still it remains same...
Raghunatha_Reddy_S 11-Jul-12 1:33am    
could you post code of javascript method that you are calling
As srnr noted, attach the handler to OnClientClick, as Button.Click is a server-side event.

Hit F12 in IE to bring up the Dev Tools.
Navigate to the Script tab and see if your JSFunctions.js it s loaded - it should show up in the combo.

If it doesn't, and you're sure the path is right and the file is actually present on disk, check the js itself for errors - there may be some syntax error that could stop it from loading correctly in the browser.
 
Share this answer
 
Comments
J.Karthick 10-Jul-12 10:52am    
i can see the <script> reference my Aspx page. But still no use.
J.Karthick 10-Jul-12 10:55am    
i have added a break point in my JS file. My Compiler get inside my JS function but not showing up the alert yet.
markovl 10-Jul-12 12:23pm    
So your function is getting called? Is there any error message? The browser may be preventing the alert. Did you try another browser?
I just drag and drop the URL of JS file inside my ASPX page
It might not work like that.

Sounds like it is relative path issue. At times, after deployment the path referenced as a source for images, stylesheets, etc is not correctly formed. This leads to no file found at the location referred because of which images don't download or style-sheets does not get applied.
You would need to make sure that the path is correct such that file is found and used.

I would suggest you to use this Tip and resolve the path correctly before setting the source of the file: Resolving Paths in a Multi-Folder WebSite[^]
 
Share this answer
 
Comments
J.Karthick 10-Jul-12 10:59am    
i'm new to VS2010, but i have used JS in VS2008 for an year.
It didn't behave like that, i always use to drag and drop my script locations. Its works fine in all conditions.

I think the problem is the framework i have changed now. Am i need to set any settings for VS2010 for JS ?
J.Karthick 10-Jul-12 11:33am    
I tried with HTML button its works fine..
Problem is with ASP button

Have you face this problem before??
Sandeep Mewara 13-Jul-12 3:19am    
I was not aware of it. Good to see you got it resolved.
I found it.


Problem is in ASP button which was designed in VS2008 and i just copy replace the page in my VS2010.


While i replace the ASP buttons....its works fine
Also check the link which was help me
http://forums.asp.net/t/1497191.aspx/1[^]


Thanks a lot for your support CP and members...
 
Share this answer
 
v2
you can used properly url
Quote:
<script src="../../Scripts/ClientDetails.js" type="text/javascript"></script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900