Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between script tag, and "<%....%>" tag?

I have just started to work on web applications, and learning to use ASP.Net. I have come across two methods to add script in an HTML page. One is by using script tag, and other one is by using <% ... %> tag. But, I am unable to figure out, what is the difference between both, and which one should I prefer in which case?

like image 437
jitendragarg Avatar asked Apr 26 '11 14:04

jitendragarg


People also ask

Whats the difference between <% and script?

The script tag is used to specify full scripts (usually complete methods/function) (mostly client side scripts but you can also have server side script blocks) while the <% ... %> are used to include server side inline snippets. Save this answer. Show activity on this post.

What is a script tag?

The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.

What are different types of script tags?

async: It is used to specify the script is executed asynchronously. charset: It is used to specify the character encoding used in an external script file. defer: It is used to specify that the script is executed when the page has finished parsing. src: It is used to specify the URL of an external script file.

What's the difference between putting script in head and body?

JavaScript in head: A JavaScript function is placed inside the head section of an HTML page and the function is invoked when a button is clicked. JavaScript in body: A JavaScript function is placed inside the body section of an HTML page and the function is invoked when a button is clicked.


3 Answers

The script tag is used to specify full scripts (usually complete methods/function) (mostly client side scripts but you can also have server side script blocks) while the <% ... %> are used to include server side inline snippets.

like image 152
Bala R Avatar answered Oct 03 '22 22:10

Bala R


The tag can be JavaScript or the language in question. The <% %> is functionally equivalent to

<script language="C#|vb" runat="server">

In general, you put the code in code behind (win forms), so the only is for client side script (generally JavaScript). With ASP.NET MVC, the <% %> is for marking up the view and is not really code.

like image 31
Gregory A Beamer Avatar answered Oct 03 '22 23:10

Gregory A Beamer


Script tags are used to add Javascript (or similar) script to the final HTML which is rendered by the browser, and hence allow client-side scripting.

<% ... %> tags are ASP tags that are processed on the server side, and will not be present in the rendered HTML.

like image 26
Jackson Pope Avatar answered Oct 03 '22 22:10

Jackson Pope