hdue
hdue

Reputation: 3

Javascript in HTML and ASP file

Since JavaScript can be written (or contained) within an HTML file or in an ASP file, is there any difference?

Upvotes: 0

Views: 179

Answers (4)

Quentin
Quentin

Reputation: 943569

ASP is a server side technology that (usually) outputs an HTML document when executed.

Any JavaScript you write might be part of the HTML document (and thus identical to any JS you might put in a static HTML document) or it might be written as server side code (in which case it will execute on the server, have access to ASP APIs instead of Browser APIs, and will generate output instead of being output).

Upvotes: 1

painotpi
painotpi

Reputation: 6996

One difference I can think of is, the way you bind HTML/ASP controls

--HTML button control--
<input type = "button" id = "myButtonHTML" />

--ASP button control--
<asp:button runat = "server" id = "myButtonASP" />

the way you bind this in javascript will be as follows

--HTML control--
document.getElementById("#myButtonHTML").value

AND

--ASP control--
document.getElementById("#myButtonASP.ClientID").value

Upvotes: 0

James
James

Reputation: 13501

The marvellous thing about Javascript and server-side programming languages like ASP and PHP is that they can be (sort of) intertwined. So, for example, if you have a server-side variable that you want to be able to mess about with using Javascript, you can include it in the JS when you output the page:

// THIS IS THE ASP CODE
string mystring = "This is my ASP string";
string html = "<script type=\"text/javascript\">var mystring = "+mystring+"</script>";
// then output the html

That's a terrible, badly-coded example, but you hopefully get the idea. You can emit Javascript to the page using ASP variables and the like. It's very handy.

Upvotes: 0

casablanca
casablanca

Reputation: 70701

ASP runs on the server-side. Any HTML or JavaScript generated by this is simply sent to the browser, which is where the HTML is rendered and JavaScript is executed.

Upvotes: 2

Related Questions