开发者

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?


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.


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


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜