Pass Variable from Content page to Master Page in classic ASP - asp-classic

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.

Related

How to prevent blank page getting added at the end of pdf report due to page break

I am printing the pdf report where i will be looping each student and i am applying page-break after each student
And my applied page break code is as below
<style type="text/css" >
.page-break { display:block; clear:both; page-break-after: always;}
</style>
And my view is
<% #students.each do |student| %>
<%= student.first_name %>
<div class="page-break"></div>
<% end %>
Problem is i am getting empty page at last in pdf report, i am using wicked-pdf gem for pdf generation i think problem is with page-break css can anyone help me
Quick and dirty solution, but should work fine:
<% #students.each do |student| %>
<%= student.first_name %>
<% if student.id != #students.last.id %>
<div class="page-break"></div>
<% end %>
<% end %>
Also if you can show us the html container of the each loop, we can give a better answer depending on this one.
Just dont add the class that gives page break on your last loop, that way "page-break-after: always" wont take effect

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 .

script tags in html

I'm having difficulties google what's the difference between the following script tags:
<%# ... %>
<% = ... %>
<% ... %>
Can someone help?
These tags also may be ASP.NET tags.
Here are links with the information about each tag:
<%# ... %> Data-Binding Expression Syntax
<%= ... %> Displaying from ASP.NET
<% ... %> Embedded Code Blocks in ASP.NET Web Pages
i don't know about the 1st one
but 2 and 3 was the jsp tag,
2 one is the expression tag like when you want to get value from jsp variable then you can use this tag
for e.g.
String arg = "Pratik"
now you want use this in jsp page anywhere
Hello <%= name %> ////// it will print on web page as Hello Pratik
the 3rd one is the script tag
when you want write block of jsp,java code you can write within this tag
for ex.
<%
String name="";
name = "abc";
out.println(name);
%>

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.

ASP Classic - Include VBScript page in a JavaScript page?

Is there a way to include a VBScript page into an ASP page written using Javascript?
There is an ASP page written in Javascript, but our sidebar menu is written in VBScript. When I include the sidebar asp file into the Javascript the server gives an error.
< %# LANGUAGE="JavaScript" %>
<%
...
< !--#include file="sidebar.asp"-->
...
where sidebar.asp is written using VBScript.
You can try this, but my guess is that the sidebar.asp will be executed before your Javascript code.
< %# LANGUAGE="JavaScript" %>
<%
...
<script language="VBscript" runat=server>
< !--#include file="sidebar.asp"-->
</script>
...
I do this all the time, but I write my ASP/JScript pages a bit differently. Instead of switching the page language to "JavaScript", I leave it at the default "VBScript" and then use a <SCRIPT LANGUAGE="JavaScript" RUNAT="Server"> block for my JScript code. The JavaScript SCRIPT blocks are executed before the normal <% %> tags, so I do all my page processing in the SCRIPT blocks and then simply plug the results into the page with <% %> tags. Here's an example:
mainpage.asp:
<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">
var name;
var address;
var phone;
function main() {
var rec = go_to_database();
name = rec.first_name + " " + rec.last_name;
address = rec.address;
phone = rec.phone;
}
</SCRIPT><% main() %>
<html><head><title><%= name %></title></head><body>
<p>Name: <%= name %><br/>
Address: <%= address %><br/>
Phone Number: <%= phone %></p>
<!--#include file="subpage.asp"-->
</body></html>
subpage.asp:
<p>Blah blah blah, some random VBScript code: <%
Dim whatever
whatever = some_silly_thing()
Response.Write(whatever)
%>.</p>
So, first IIS processes the SSI and includes subpage.asp into mainpage.asp. Then, it evaluates the JScript SCRIPT block, declaring the variables name, address, and phone and defining the function main.
Then it evaluates each <% %> tag in order. <% main() %> call the main function and sets values for name, address, and phone. Then <%= name %>, <%= address %>, and <%= phone %> substitute those values into the page. Finally, the <% %> code from subpage.asp is evaluated and the Response.Write value ends up in the page output.
While the whole page is not written in JScript, the vast majority of the code can be, inside the SCRIPT block. Would that work for you?

Resources