Use server events to create custom headers and footers

Tips submitted by ASPMaker users

Use server events to create custom headers and footers

Postby squeek » Sat Aug 23, 2014 8:38 am

I'm working on a large project that uses four separate web addresses for four different functions, but all hitting the same database. I needed to be able to put help text in the header, and/or in the footer of some of my list/add/edit/view pages for some of my tables, AND I needed the help text in three languages, AND I needed the client to be able to enter that help text themself on their admin site, so I made it data driven.

Table helptext
Fields id - identity, tablename nvarchar(50), pagenvarchar(50), headfootnvarchar(50), English nvarchar(max), Spanish nvarchar(max), Vietnamese nvarchar(max)

Tablename should hold the name of the table or view. Headfoot can be head or foot.
Page can be list, add, edit, or view. For example, for a header on the list page of the applicants table, the record would look like this:

tablename:applicants
page:list
headfoot:head
and then the english text, spanish text, and vietnamese text

This is a pretty simple layout. Now for the code.

In the global/all pages/page_head code, add these functions:

function gethelp(table, page, headfoot, language)
dim strsql
strsql="SELECT " & language & " as helptext from helptext where lower(tablename)='" & lcase(table) & "' and lower(page) = '" & page & "' and lower(headfoot) = '" & lcase(headfoot) & "'"
gethelp=replace(ew_ExecuteScalar(strsql) & "",vbcrlf,"<br><br>")
end function


sub showhelp(table, page, headfoot)
if gethelp(table, page, headfoot, "english") & gethelp(table, page, headfoot,"spanish") & gethelp(table, page, headfoot, "vietnamese") & "">"" then %>

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#help<%=headfoot%>" ).tabs();
});
</script>

<div id="help<%=headfoot%>">
<ul>
<li><a href="#help<%=headfoot%>-1">English</a></li>
<li><a href="#help<%=headfoot%>-2">Spanish</a></li>
<li><a href="#help<%=headfoot%>-3">Vietnamese</a></li>
</ul>
<div id="help<%=headfoot%>-1">
<%=gethelp(table, page, headfoot,"english")%>
</div>
<div id="help<%=headfoot%>-2">
<%=gethelp(table, page, headfoot,"spanish")%>
</div>
<div id="help<%=headfoot%>-3">
<%=gethelp(table, page, headfoot,"vietnamese")%>
</div>
</div>
<%
end if
End Sub


For each table and page where you might want a header or footer, enter this into the Page_DataRendering sub:

showhelp "applicants","list","head"

and this into the Page_DataRendered sub:

showhelp "applicants","list","foot"

Make sure you enter your tablename and page type as appropriate.
squeek
 
Posts: 31
Joined: Fri Nov 22, 2013 2:31 am

Return to User Submitted Tips (ASPMaker)