Solved

How to organize javascript function and how to call it when we want to use it?

Posted on 2007-12-06
8
585 Views
Last Modified: 2012-08-13
Hi,

I am using asp net and vb code.

Let say I have some javascript function, and I want to put it some where.

My question are:

1. Where the best place to put it?
2. How to use it in vb behind code and aspx inline code?

Please help.

Thank you.
0
Comment
Question by:emi_sastra
8 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20418736
IT all depends on you where you want to call that javascript function according to its usage.
Like onClick of button or onChange of drop down etc etc in aspx front end.

But the javascript cannot be called in the vb code behind for use.
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20418917
create a .js file in your project and put all your javascript functions and give the reference in your .aspx page like this:

<SCRIPT LANGUAGE='JavaScript' src="~/Scripts/filename.js></SCRIPT>

then you can call any function from .aspx page after you have reference.

hth
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 20419325
Hi, Nisarkhan

Should I put th <SCRIPT LANGUAGE='JavaScript' src="~/Scripts/filename.js></SCRIPT> in every page of aspx form or I just put in Master.Page.

Thank you.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:emi_sastra
ID: 20419340
Hi asvforce,

It is possible to call javascript function in vb behind code.
We could do it using something like txt.attribute.add

Thank you.
0
 
LVL 7

Accepted Solution

by:
nisarkhan earned 500 total points
ID: 20419409
just put in the master.page and it will inheirts to all your content pages

let me know if you have any other issues.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 20419486
Hi, Nisarkhan,

Thank you. I have a postback problem.
I have a gridview which contain several textbox, on a certain textbox when textchanged I need to do some validation.

My problem is when I set the textbox autopostback property to true then when user press Enter key then it will submit the form (Save button is triggered).

How do I overcome this problem. What I hope is the user still could press Enter key but there is no submit or posback, but I also could do some validation.

What in my mind is I could set the Enter key event to Tab when Enter Key is press.

Please help how to solve this problem using vb code or javascript.

Thank you.
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20421256
your orginal question is "organize javascript function and how to call..." and i answer to that but now you asking totaly different question, close this question and ask as a new question.

hth
0
 
LVL 3

Expert Comment

by:caseyrharris
ID: 23449096
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question