How To Import Javascripts on Asp.net Pages

I had a serious problem with some Javascript functions and I found that there is some way to import the scripts in your asp.net pages. And each one will act different than another one.

—————————————————————-

GNU Logo

GNU Logo

‪Title : How To Import Javascripts on Asp.net Pages

‪Publish Date : 02/22/2010

‪Version : 1.0

‪Author : Nasser Hajloo

‪Author Mail :  n.hajloo@gmail.com

‪Copyright (c) 2010 Nasser Hajloo.

‪Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation;

‪with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.

—————————————————————-

As you all know Javascript is Script language which used in web pages to do some client activities. In addition Asp.net is a Server side Language which control users behavior on server and get necessary feedback to him/her.

With this background we understand that Javascript will do some thing on client, And there is two way to use javascripts code in Asp.net pages. Classic Asp ( .Net 1.0 ) used a bad scenario to work with scripts, It imports scripts insode of Asp page and every peace of script codes in every postback comes from server to client and it cause to increase page size. In this scenario all JS files putted on a HTM/HTML page and this page imported on Classic Asp page.

 

<!--#include virtual="JS.htm" -->

The <!–#include virtual=”JS.htm” –> is server side include, won’t work without certain configurations and is included by the server there and then already whereas javascript’s way is loaded into the page. Server Side Includes (SSI) is a simple interpreted server-side scripting language used almost exclusively for the web. (You can get more info at Wikipedia )

The above code increase page size and end-user may got crazy. So there should be a good solution to reduce the page size. Asp.net use another approach to use scripts.

In Asp.net Pages Java script codes has a JS file template. And you can write your codes inside it, Then you can ipmort it in your Asp.net page and when Asp.net page downloads to users computer, JS files are downloading in users computer Temp directory.

This approach will reduce page size and let Asp.net page load much faster than classic Asp pages. So to do this, all you need is addresssing JS file in your Asp.net Pages.

 

<script src="myjavascript.js" type="text/javascript"></script>

 

The above code will download MyJavaScript.JS file tousers Temp Directory and every Asp.net pages which address it, will use this file. So you address every where anddownload just one file to users computer.

One Response to How To Import Javascripts on Asp.net Pages

  1. KiaMarket says:

    سلام
    خسته نباشی
    ممنون از مطالب خوبت
    اما کاش فارسی هم نوشته بودی اینو !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: