Solved

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

Posted on 2007-12-06
8
586 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

821 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