Solved

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

Posted on 2007-12-06
8
588 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
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…

687 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