Solved

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

Posted on 2007-12-06
8
583 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 34
Exit the loop 4 40
Change javascript css 1 21
Gridview alignment 1 12
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

863 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

18 Experts available now in Live!

Get 1:1 Help Now