ASP include file into variable - asp.net

I have a template.aspx file the contains code like this:
<html>
....
<body>
<div id="wrapper">
<div id="container">
----sideMenu---
.........
<div id="body">
<%=pageContent%>
</div>
</div>
</body>
</html>
I have a file index.aspx
with the code:
<%
Dim pageContent = ""
%>
<!--#include virtual="template.aspx"-->
I want to insert in pageContent a lot of html code and asp code
without connecting strings like this:
pageContent = "<div class..." &_
" bla bla bla " & aspVariable &_
"more divs and html and asp variables"
.
.
.
actually i want a dyanmic pages i dont want write the template html codes each pages i want that only the pageContent are change.

It would be more common to create a handful of template files to be included in each page of your ASP app. Such as:
header.inc (might contain site, banner... top of page stuff)
topNav.inc (might contain code to generate the top navigation bar)
leftNav.inc (take a guess ;))
bottomCopy.inc (might have text links as site map and copyright statement.
Then, in each page, include all where they should live. For example, in my page called "theFirst.aspx", I might have:
<!-- #include file = "cacheprevent.inc" -->
<!-- #include file = "accesscheck.inc" -->
<!-- #include file = "header.inc" -->
<!-- #include file = "topNav.inc" -->
<!-- #include file = "leftNav.inc" -->
<%
' Here goes the rest of your code to generate content for this specific page
%>
<!-- #include file = "bottomCopy.inc" -->
All this assumes it is in ASP-Classic, as you've tagged your post, at least in part.
... and you could in some cases, combine the top four... if all pages would have the same layout regions.

Related

Missing index file Brackets IDE

This is a question which I'm not fully understanding. I need further insight and I have been unable to find it elsewhere.
Hello everyone. I'm getting an error in the brackets IDE that looks like this http://imgur.com/WccBRtf . I don't understand at all what's going on here, and that's because I don't know what an HTML5 index file really is. The file I have named index.html is just the main HTML5 code for a webpage I wan't to run. The file is as follows
<head>
<!-- Title of webpage -->
<title>
Name of Guild
</title>
<!-- Link the CSS file so that the html5 can display it -->
<link rel = "Stylesheet" type = "text/CSS" href = "GuildPageStyle.css">
</head>
<!-- Main Body of the page -->
<body>
<!--Post section-->
<div class = "PostsSEC">
<!-- The way to display multiple posts is to go through a while loop counting up until all posts have been displayed with the current pots being displayed being equal to the current post in the while loop -->
<p id = "PostMain">
*A post*
</p>
<!--This is not the image, this is box it is in-->
<p id = "PostPosterBoxOR">
< ORIGINAL
<br />
POSTER
</p>
<p id = "PostPosterBoxBL">
</p>
<!--The next section is totally reliant on a server side language. This is the likes and votes by other powered members of the group-->
<div id = "EndMessage">
<!-- Message at the end of the posts declaring that it is the end -->
<h1 id = "PostsEnd">
That's all the current posts
</h1>
<!-- Change the something Missing to a link after completion -->
<h3 id = "ErrorCheckPostEnd">
Something Missing?
</h3>
</div>
</div>
<!--Profile/Users/Follower barier-->
<div id = "Bar">
</div>
<div id = "BackgroundBlock">
</div>
<img src = "http://i.imgur.com/64cUAcH.png" id = "GuildLogo" />
<!--The group of users-->
<div id = "Users">
<!--Replace this section with PHP reliant on the users-->
</div>
<img src = "https://pbs.twimg.com/profile_images/855649567756476416/OHQKYYvY_400x400.jpg" id = "ProfileOne" />
<img src = "https://pbs.twimg.com/profile_images/855649567756476416/OHQKYYvY_400x400.jpg" id = "ProfileTwo" />
<img src = "https://pbs.twimg.com/profile_images/855649567756476416/OHQKYYvY_400x400.jpg" id = "ProfileThree" />
<img src = "https://pbs.twimg.com/profile_images/855649567756476416/OHQKYYvY_400x400.jpg" id = "ProfileFour" />
<img src = "https://pbs.twimg.com/profile_images/855649567756476416/OHQKYYvY_400x400.jpg" id = "ProfileFive" />
<img src = "https://pbs.twimg.com/profile_images/855649567756476416/OHQKYYvY_400x400.jpg" id = "ProfileSix" />
<div id = "BackgroundBlockade">
</div>
<p id = "BioBlock">
This is a bio
</p>
</body>
Now up until yesterday I was fully able to run the file in brackets. Then, for seemingly no reason from my perspective, I became unable to run the code. After it stopped working I changed the name of the HTML5 file to index.html and kept the CSS file exactly the same. I have no idea what's going on, and have been able to understand nothing.
I realize to the more experienced programmer this may seem like a question similar to "Why isn't this code running" when all that's wrong is that they forget to do "std::" instead of just writing out "endl". I'm very new to HTML5 and am completely lost here. I thank you for your time. Have a nice evening.
Here is another image to aid
http://imgur.com/QELF7Ts
(Yes I did try removing the "HTML5 guild page html.html")
So I have resolved the issue. By opening the project as a folder instead of one singular file at a time i managed to succeed in resolving it. Problem solved

Pass Variable from Content page to Master Page in classic ASP

I am new to classic ASP and I am trying to create a Master Page with variable placeholders and fill the information on that page with variables that are worked on a content page.
my master page looks like this:
<html>
<head>
<title>Template Loaded Properly</title>
</head>
<body>
<% call BodyContent %>
<span>Title: <% //place title here %></span>
<span>Content: <% //place content here %></span>
</body>
</html>
and the content page like this:
<!--#include virtual="/templates/TEMPLATE.html" -->
<% sub BodyContent %>
var Title = "This is the title"
var Content = "Here goes some content"
<% end sub %>
Any help will be appreciated.
Once you include the page with the variables, you can treat them as if they were created right then and there (because in a sense they are created right then and there, at least from the server's point of view). You do need to make the variables global in scope [read: dim them outside the sub], unless you want to list all of them when calling your BodyContent sub. (Personally, I don't see the point, but some people are unreasonably allergic to global variables.)
<%
dim Title, Content
sub BodyContent
Title = "This is the title"
Content = "Here goes some content"
end sub
%>
<body>
<% call BodyContent %>
<span>Title: <%=Title%></span>
<span>Content: <%=Content%></span>
</body>
One caveat, though: include files are processed long before the code, so you can't vary what file is included. In other words, don't do this:
<%If x = a Then%>
<!-- #include virtual="/templateA.inc" -->
<%Else%>
<!-- #include virtual="/templateB.inc" -->
<%End If%>
The result of trying something like that is that both templateA and templateB will be included. If you need conditional includes, look into using FileSystemObject to read the content of the appropriate template, and then using Execute to, well, execute it.

change frames/iframes to just one page #aspclassic

How do I rewrite the following PHP code in Classic ASP?
<head></head>
<body>
<h1>Test</h1>
<section><?php echo include('content/'.$_GET['p'].'.php') ?></section></body>
If the url is http://foo.bar.com/admin.php?p=pages, then content/pages.php is shown.
You can't do this with INCLUDE but you could use Server.Transfer instead, eg.
Server.Transfer "content/" & Request.Form("p") & ".asp"
Never trust what comes from the clientside (browser) as they can try to hack you.
Since it is not likely that "shdyhio3hlkehio.asp" or similar is a proper file, you should limit the options to your actual selection and also have a default file which is a "catch all other requests".
Combine that with Server Side Includes and you have your setup ready.
You should also check if the user actually requested a page -- if "p" is empty then show a default message.
Note the use of LCase in the "Select Case"-line and lowercase values in the Case-lines.
This is due to the face that the string comparison is case-sensitive, meaning "about" (lowercase "a") and "About" (uppercase "A") is not the same.
Eksemple:
<% If Request.QueryString("p") = "" Then %>
no specific page was request, show a default message
<% Else %>
<% Select Case LCase(Request.QueryString("p")) %>
<% Case "content" %><!-- #include file="content.asp" -->
<% Case "about" %><!-- #include file="about.asp" -->
<% Case "contact" %><!-- #include file="contact.asp" -->
<% Case Else %><!-- #include file="404.asp" -->
<% End Select %>
<% End If %>
You can use something like this
<!--#include file="somefile.asp"-->
in your HTML file .

VBscript pass parameters to included file

Ok, I'm new to the asp/vbscript world. I am working at a new company and am trying to reproduce a script I use on almost all projects when developing under php.I have two functions one called showHeader and one called showFooter. These functions both get arguments passed to them and those arguments need to be displayed in the included file. For example in php my showHeader function is like so
<?php
showHeader($page,$title,$passedCSS,$desc,$keywords) {
include("header.php");
}
?>
Now in the include file i can echo out the contents of any of those arguments simply by calling echo $var and i get the contents. Is this possible with vbscript. I'm having no luck what so ever.
#projectxmatt: You could do something like --
In header.asp:
<%
Sub showHeader(page, title, passedCSS, desc, keywords)
%>
<!-- some HTML code here -->
<title><%=page %></title>
<!-- more HTML code here -->
<%
End Sub
%>
In somefile.asp:
<!-- #include file="header.asp" -->
<% showHeader "value-for-page", "My Page Title", "", "", "" %>
With ASP you have to specify all the variables you have in your Sub or Function, they can't be left out or assigned with a default as in PHP if none was passed to the function (e.g. function showHeader(title = 'Default Value'))
Ok here is what i did
global.asp
<%#LANGUAGE="VBSCRIPT"%>
<%
Sub showHeader(page,title,passedCSS,desc,keywords)
%>
<!---#include file="header.asp"--->
<%
end Sub
Sub showFooter(passedJS)
%>
<!---#include file="footer.asp"--->
<%
end Sub
%>
Then in header.asp and footer.asp I passed in the vars just using <%=varname%>
Then in the main.asp my code was as follows.
<!---#include file="global.asp"--->
<% showHeader "Home","Test Page","test.css","Description","keywords" %>
<section>
</section>
<aside>
</aside>
<section>
<h2></h2>
<ul>
<li><article></article></li>
<li><article></article></li>
</ul>
</section>
<section>
<div></div>
<div></div>
<div></div>
</section>
<% showFooter "testjs.js" %>
And everything works great.
Response.Write would be another solution you could use to write output in classic ASP.

Escaping inline code block in Asp.Net template

I have a page where I wish to render the following html (a small JS template)-
<script type="text/html" id="lightbox-template">
<div id="lightbox-background"></div>
<div id="lightbox"><%= content %><div class="bottom"></div></div>
</script>
However, the Asp.NET preprocessor is picking up on the "<%=" tag and trying to interpret it. I wish to escape this tag to allow it to be rendered, preferably from the template rather than the code behind. Is this possible?
I have managed to do this via a Literal control and setting it's text in the code behind.
I ideally wanted to keep it within the aspx page. This is the best solution I could find (from here), which creates splits the closing > into a separate string
<script type="text/html" id="lightbox-template">
<div id="lightbox-background"></div>
<div id="lightbox"><%= "<%= content %" + ">" %=><div class="bottom"></div></div>
</script>
Important bit: <%= "<%= content %" + ">" %=>
This goes into aspx
<div> <%= GetContentString() %> </div>
This goes into aspx.cs
protected String GetContentString()
{
return "this is a content";
}

Resources