Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2008, 09:02 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default how to include .js file in .aspx page

hi,
  in my page i have 18 controls,to validate these controls i written one js file.i am not getting how to call that js file in my aspx page.
i included js file like this
<script language="javascript" src="../javascript/abc.js" ></script>

up to here fine.i stuck here.should i assign methods of js file in code behind ?or in aspx page ? what should i do?please any one can help me.

i am developing my site with vb.net.
__________________
shanwaj
 
Old March 7th, 2008, 09:25 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It doesn't matter.

You can add the JS methods at the design level or add the methods to your controls in the code behind using <control>.Attributes.Add("<event>", "<method>")

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 8th, 2008, 01:34 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

hi dparsons,
 sorry for my late reply. Thanks for your reply.ya I added method of js file in code behind part like
  button1.Attributes.Add.("onclick","return validate()").
 I tried this but it is not calling the methods.Simply the page was getting postback.I googled regarding this from past two days. but i did not get solution.Please give me a small example of this.

once again thanks for your reply.
 
Old March 8th, 2008, 01:31 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It sounds like the path you have supplied as the value for src is incorrect.

<script language="javascript" src="../javascript/abc.js" ></script>

Is this how your file structure looks:

root
     folder:javascript
          abc.js
     folder:somefolder
          page.aspx

That is how your structure would need to look for the SRC attribute to be correct, otherwise the JS file will not be included on the page.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 9th, 2008, 11:19 PM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

good morning dparsons,
thanks for your reply,sunday is holiday to me,so that i couldn't see your reply.
 i read your article regarding how to get correct answers.you are right.in which way we are asking the question,in that same way we get our answers.i agree with you,we people need to brush up our English language which communicate with all over world.i will learn good English .
 you said that src path has incorrect.in src path javascript is the folder name which is having js file. should i need to include page also here.
in many solutions they given like src="/folder/file.js" only.i am trying for this.To solve this i am trying in so many ways.please give me one small example.i am very thankful to you.
 
Old March 10th, 2008, 07:40 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Give the file structure in my previous post, a SRC attribute with these values should correctly add the js to your page:

/JavaScript/abc.js

I suggest using the above path since it should evaluate correctly regardless of where your page is physcially located in the file structue.

This should also work if your page exsits as I demonstrated in my previous post:
../JavaScript/abc.js

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 10th, 2008, 09:02 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

hi goodevening,
  my page is located in one folder called admin and js located in another folder called JavaScript.
now i tried in two ways.
1. <script language="javascript" src="../JavaScript/dkvendrg.js"></script>
    <asp:Button ID="btnAdd" Text="Add" OnClientClick="return vendvalidate();" runat="server" Width="64px" Height="24px" />

2. btnAdd.Attributes.add("onclick","javascript:vendva lidate()")

i need to include nearly 4 js file to different pages in my site.so that i am running behind js file. please help me

have a nice evening
 
Old March 10th, 2008, 09:25 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

sorry for saying this , i am leaving now, i will see your reply ,i tried this in many ways,please give one small example of it,
 you asked me root of the js right,
 root:wbfolder
   folder:JavaScript
     file:dkreg.js
thanks for your reply.
 another thing is that, i read your article regarding how to ask smart questions,its take some time to brush up my skills,
thanks once again
 
Old March 10th, 2008, 07:24 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

There really isn't an example I can give you outside of this:

<SCRIPT LANGUAGE="JavaScript" SRC="/JavaScript/dkreg.js">
</SCRIPT>

That should link any of your pages to your JavaScript file.

You say that your JavaScript functions don't fire, what is the JavaScript error you recieve?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 11th, 2008, 12:02 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

hi good morning,
  i am not getting any error here.when i click the button ,it is simply performing the action whatever i given.it is not firing any validation functions here.in my js validations i am not allowing end users to insert null values and non validate data.in js file most of all i am passing control id like document.getElementId("controlId") here.should i pass id values to functions.





Similar Threads
Thread Thread Starter Forum Replies Last Post
To include a js file into another js file jdang67 Javascript 4 February 28th, 2008 03:32 AM
Google Maps JS in ASPX page error kingroon ASP.NET 2.0 Basics 0 December 7th, 2007 09:52 AM
Dynamically include an aspx page ndkicha_1981 General .NET 0 October 19th, 2007 03:12 AM
HelpX_x; How do I include a variable file in aspx? CSharp1314 Classic ASP Basics 16 May 5th, 2004 06:15 PM
Include file within aspx jieli1001 ASP.NET 1.0 and 1.1 Professional 2 July 29th, 2003 04:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.