Solved

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

Posted on 2007-12-06
8
582 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Accepted Solution

by:
nisarkhan earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now