It’s been a long time since I dabbled server-side, but it seems to me that scripts embedded in an included code file should execute as normal. This doesn’t seem to be the case for some reason.
(Note– The below is obviously a simplified implementation based on my attempts at debugging. I’ve actually got other includes with flat HTML and JavaScript in the actual project that render just fine. It’s just ASP code that is not being parsed properly, <% %> tags and all.)
INDEX CODE
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Site</title>
</head>
<body>
<% Response.WriteFile ("includes/test.aspx") %>
</body>
</html>
INCLUDED CODE
<% response.write("boo"); %>
The resulting page, when run from a server, includes the file just fine… but the script is rendered as text.
Where have I gone wrong here??
Thanks so much for your help.
Nothing is going wrong.
When you
WriteFile, the contents of the file is going to be rendered.ASP.NET doesn’t have a facility for sever side includes the way classic ASP did.
You need to use controls to build up a page dynamically, though you may want to look at ASP.NET/MVC instead of WebForms, as it is closer to how you would have done things with classic ASP.