0

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

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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.

1 Comment

Thank you also, great example :) wish I can give you a tick also :(
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.