Re: Lots of Response.Writes of HTML - How do YOU do it?
From: Harag (haragREMOVETHESECAPITALS_at_softhome.net)
Date: 08/12/04
- Next message: mark | r: "OT - XP SP2"
- Previous message: Evertjan.: "Re: return single value in asp/sql"
- In reply to: TinyTim: "Re: Lots of Response.Writes of HTML - How do YOU do it?"
- Next in thread: TinyTim: "Re: Lots of Response.Writes of HTML - How do YOU do it?"
- Reply: TinyTim: "Re: Lots of Response.Writes of HTML - How do YOU do it?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 12 Aug 2004 11:01:02 +0100
On Wed, 11 Aug 2004 15:35:42 -0700, TinyTim <TinyTim@MissVicky.com>
wrote:
>I'm looking at Snitz forum code for my examples, one of which I
>included in this post. Even with your described methods, it seems
>like a lot of work, having to design the page layout manually then
>putting the appropriate quote marks, underscores, etc in code.
>
>>For example <%=whatever%> instead of <%Response.Write(whatever)%>
>I'll be checking this method out on one of the online tutorials. Can
>you point me to a specific tutorial?
>
>Thanks,
>
>tt
Welcome to the world of web development where typing is essential :)
I have a Include file that I include into EVERY .asp page, this file
has several functions that I use things like:
out(); // I use this instead of Response.Write
debugOut() // this is to display variable data etc. and if I
forget to take it out its not shown on the live server.
onLocalServer(); // this returns true if the site is running on my
test server
I'll include the file below incase its of any interest to you. Note
that its all in JScript. Sorry for all the tabs, I can't be bothered
to change them to spaces. copy & paste into notepad.
HTH
Al
<%
//*******************************************************************************
//* F U N C T I O N S / S U B S
//*******************************************************************************
var g_bDebug; // t/f whether in debugging mode or not.
//*******************************************************************************
/* This function to saftly convert a VBscript array into a JS 1
Dimension array
a VBscript array will normally be returned when using the ADO
"Recordset.GetRows()" method - like in the clsDBErrorChecker.asp File
it adds 2 custom properties to the Jscript Array called
"numberOfRows" &
"numberOfColumns" if no array is return from the RS.GetRows() method
(eg a DBerror)
then it will return a "string" which this JS function detects and
returns an
array with nothing in it so check if arrayname.length >0 before use.
*/
function VB_JSarray(aVBArrayFromDBCheck_OpenIntoArrayMethod,
displayDebugInfo) {
if (typeof aVBArrayFromDBCheck_OpenIntoArrayMethod !=
'string') {
vbRowsArray = new
VBArray(aVBArrayFromDBCheck_OpenIntoArrayMethod);
var numberOfColumns = vbRowsArray.ubound(1) + 1;
var numberOfRows = vbRowsArray.ubound(2) + 1;
var rowsArray = vbRowsArray.toArray();
rowsArray.rows = numberOfRows;
rowsArray.cols = numberOfColumns;
if (displayDebugInfo) {
debugOut('{HEAD}VB_JSarray()', 'Rows=' +
rowsArray.rows, 'Columns=' + rowsArray.cols, 'rowsArray=' +
rowsArray);
}
} else {
var rowsArray = Array();
rowsArray.rows = 0;
rowsArray.cols = 0;
}
return rowsArray;
}
//*******************************************************************************
// Are we in debug mode?
function inDebugMode() {
if (typeof g_bDebug == 'undefined') {
g_bDebug = false;
if (onLocalServer() ||
Request.QueryString('debug').Count > 0) {
g_bDebug = true;
}
}
return g_bDebug;
}
// This debug accepts any amount of arguments with no [] around the
text
// and creates a long html string accordingly to display the info.
function debugOut() {
if (inDebugMode()) {
var sDebugWord = 'GUBED';
var sOutput = sDebugWord, sText='';
if (arguments.length < 1) {
sOutput += '<span style="background:#555;
color:#CCC; font: bold italic 12px Comic Sans MS, Verdana;">{NO
ARGUMENTS FOR THE DEBUG FUNCTION} </span>';
} else {
for (var i = 0; i < arguments.length; i++) {
sText = String(arguments[i]).trim();
// If blank text or <br> text then
display a blank line
if (sText && sText != '' && sText !=
'<br>' && sText != '\r\n') {
// Do the debug title.
if
(sText.toUpperCase().substring(0, 6) == '{HEAD}') {
sText =
sText.toUpperCase();
}
// highlight the "=" sign.
This is done first as the "=" sign appears in all the
// properties of HTML (eg
style="")
sText = sText.replace(/=/g,
'<span style="font-weight:bold; color:#F90;">=</span>');
// If its a Header debugOut
then change color.
if (sText.substring(0, 6) ==
'{HEAD}') {
sText = '<span
style="font-weight:bold; color:#CCC;">' + sText.substring(6) +
'</span>';
}
// If its a highlight debugOut
then change the color from the default.
sText =
sText.replace(/{HIGH}/gi, '<span style="color:#F90; font: bold 12px
Verdana;">');
sText =
sText.replace(/{\/HIGH}/gi, '</span>');
// if the text isn't
surrounded with {...} then add the brackets to the
// front and the back of the
string
if (sText.charAt(0) != '{') {
sText = '{' + sText;
}
if
(sText.charAt(sText.length-1) != '}') {
sText += '}';
}
// if there is no info after
the "=" then insert word "EMPTY"
sText =
sText.replace('=</span>}', '=</span><span style="font: bold 12px
Verdana;; color:#C00;">EMPTY</span>}');
var sText = '<span
style="background:#555; color:#0BB; font:12px Verdana;">' + sText +
' </span>' ;
// If there is more than 5
elements then wrap the output every 5 elements.
if (i % 5 == 4 && i !=
arguments.length-1) {
sText += sDebugWord;
}
// Add the created string to
the total output string
sOutput += sText;
} else {
sOutput += '<br>';
}
}
}
// Change all the [.] & {.} in the output string to a
differnt color so they stand
// out better from the rest
sOutput = sOutput.replace(/(\[|\])/g,'<span
style="font-weight:bold; color:#0CC;">$1</span>');
sOutput = sOutput.replace(/(\{|\})/g,'<span
style="font-weight:bold; color:#FC0;">$1</span>');
// Change the word {DEBUG} so the debug title stands
out better.
sOutput = sOutput.replace(/GUBED/g,'<br><span
style="background:#600; color:#C00; font: bold 12px Comic Sans MS,
Verdana;"> { DEBUG } </span>');
// Output the final string.
out(sOutput);
}
}
//*******************************************************************************
// only display when in debug mode as defined in inDebugMode() above
// this is to add a touch of color to any debug strings.
function debugHighlight(sText) {
if (inDebugMode()) {
if (sText && sText != '') {
sText = '{HIGH}' + sText.trim() + '{/HIGH}';
}
}
return sText;
}
//*******************************************************************************
// Justs puts a comment to the HTML file for easy reading
function debugOutHeader(sHeader, bMainHeader) {
var sNewHead = '', sTxt;
if (inDebugMode()) {
sHeader = String(sHeader).toUpperCase() || "No Header
Text";
if (sHeader.length > 0 ) {
if (bMainHeader) {
for (var i = 0; i < sHeader.length;
i++) {
sNewHead += sHeader.charAt(i)
+ ' ';
if (sHeader.charAt(i) == ' ')
{
sNewHead += ' ';
}
}
sNewHead=sNewHead.trim();
sTxt = '\r\n<!--\r\n';
sTxt +=
'************************************************************\r\n';
sTxt += '*************** ' + sNewHead
+ ' ***************\r\n';
sTxt +=
'************************************************************\r\n';
sTxt += '-->\r\n';
} else {
sNewHead = sHeader;
sTxt = '\r\n<!-- [DebugHeader]
********** ' + sNewHead + ' ********** -->\r\n';
}
out(sTxt);
}
}
}
//*******************************************************************************
// simple wrapper for Response.Write,
function out(sText) {
Response.Write (sText);
if (inDebugMode()) {
Response.Write ('\r\n');
}
}
//*******************************************************************************
// OutJS is mainly used for outputting JS files as these are easier
with
// returns & linefeeds.
function outJS(sText) {
Response.Write (sText + '\r\n');
}
//*******************************************************************************
// use Response.Redirect or Server.Transfer depending on ASP version
function redirect(sDestination) {
// use expensive round-trip redirect always
// Server.Transfer caused problems
Response.Redirect (sDestination);
}
//*******************************************************************************
// to return the html code for a transparent image of iWidth, iHeight
function pixelImage(iWidth, iHeight) {
if (iWidth < 1 || !iWidth) {
iWidth = 1;
}
if (iHeight < 1 || !iHeight) {
iHeight = 1;
}
return '<img src="/Images/Pixel.gif" width="' + iWidth + '"
height="' + iHeight + '" alt="" border="0">';
}
//*******************************************************************************
function closeWindow(bCentered) {
var sText = '';
if (bCentered) {
sText = '<div style="text-align:center; margin:10px;
2px;">';
}
sText += '<span class="Font01">[ <a href="#"
onclick="window.close(); return false;">Close
Window</a> ]</span>';
if (bCentered) {
sText += '</div>';
}
return sText;
}
//*******************************************************************************
function closeWindowAndOpener(bCentered) {
var sText = '';
if (bCentered) {
sText = '<div style="text-align:center; margin:10px;
2px;">';
}
sText += '<span class="Font01">[ <a href="#"
onclick="window.close(); window.opener.close();return false;">Close
Window</a> ]</span>';
if (bCentered) {
sText += '</div>';
}
return sText;
}
//*******************************************************************************
function userErrorMessage(sErrorText) {
// Note you need the SFX.CSS file included for this to look
right.
return '<div class="bg900 Bordered Font02" style="padding: 0em
1em; text-indent: -1em;"><span class="bg600 Font04" style="color:#C00;
font-weight: bold;"> ERROR: </span> ' + sErrorText +
'</div>';
}
//*******************************************************************************
// Convert a string to a Base10 number, if it cannot be converted then
return
// the devault value. This is used to make sure that input from web
forms are
// actually numbers and not string... eg Age, quantity. etc.
function convertToNumber(sString, iDefault) {
var iNewVal = parseFloat(sString, 10) || iDefault || 0;
sString = (''+sString).toLowerCase();
if (sString == 'true' || sString == 'yes' || sString == 'on')
{
iNewVal = true;
}
if (sString == 'false' || sString == 'no' || sString == 'off')
{
iNewVal = false;
}
if (isNaN(iNewVal)) {
iNewVal = iDefault;
}
return iNewVal;
}
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
%>
>
>'--------------- Code Snippet Follows --------------------------------
>else
> Response.Write " <p><font face=""" & strDefaultFontFace
>& """ size=""" & strHeaderFontSize & """>You do not have permission to
>change another users subscription. Only Administrators may change
>another users subscriptions.</font></p>" & vbNewline
>
> ' ## This is just the form which is used to login if the
>person is
> ' ## not logged in or does not have access to do the
>moderation.
> Response.Write " <form
>action=""pop_subscription.asp?UserCheck=Y"" method=""post""
>id=""Form1"" name=""Form1"">" & vbNewline & _
> " <input type=""hidden""
>name=""REPLY_ID"" value=""" & ReplyID & """>" & vbNewline & _
> " <input type=""hidden""
>name=""TOPIC_ID"" value=""" & TopicID & """>" & vbNewline & _
> " <input type=""hidden""
>name=""FORUM_ID"" value=""" & ForumID & """>" & vbNewline & _
> " <input type=""hidden"" name=""CAT_ID""
>value=""" & CatID & """>" & vbNewline & _
> " <table border=""0"" width=""75%""
>cellspacing=""0"" cellpadding=""0"">" & vbNewline & _
> " <tr>" & vbNewline & _
> " <td bgcolor=""" &
>strPopUpBorderColor & """>" & vbNewline & _
> " <table border=""0""
>width=""100%"" cellspacing=""1"" cellpadding=""1"">" & vbNewline
> if strAuthType = "db" then
> Response.Write " <tr>" & vbNewline & _
> " <td bgColor=""" &
>strPopUpTableColor & """ align=""right"" nowrap><b><font face=""" &
>strDefaultFontFace & """ size=""" & strDefaultFontSize & """>User
>Name:</font></b></td>" & vbNewline & _
> " <td bgColor=""" &
>strPopUpTableColor & """><input type=""text"" name=""name"" value="""
>& strDBNTUserName & """ size=""20""></td>" & vbNewline & _
> " </tr>" & vbNewline & _
> " <tr>" & vbNewline & _
> " <td bgColor=""" &
>strPopUpTableColor & """ align=""right"" nowrap><b><font face=""" &
>strDefaultFontFace & """ size=""" & strDefaultFontSize &
>""">Password:</font></b></td>" & vbNewline & _
> " <td bgColor=""" &
>strPopUpTableColor & """><input type=""password"" name=""password""
>value="""" size=""20""></td>" & vbNewline & _
> " </tr>" & vbNewline
> else
> Response.Write " <tr>" & vbNewline & _
> " <td bgColor=""" &
>strPopUpTableColor & """ align=""right"" nowrap><b><font face=""" &
>strDefaultFontFace & """ size=""" & strDefaultFontSize & """>NT
>Account:</font></b></td>" & vbNewline & _
> " <td bgColor=""" &
>strPopUpTableColor & """><input type=""text"" name=""DBNTUserName""
>value=""" & strDBNTUserName & """ size=""20""></td>" & vbNewline & _
> " </tr>" & vbNewline
> end if
> Response.Write " <tr>" & vbNewline & _
> " <td bgColor=""" &
>strPopUpTableColor & """ colspan=""2"" align=""center""><Input
>type=""Submit"" value=""Send"" id=""Submit1"" name=""Submit1""></td>"
>& vbNewline & _
> " </tr>" & vbNewline & _
> " </table>" & vbNewline & _
> " </td>" & vbNewline & _
> " </tr>" & vbNewline & _
> " </table>" & vbNewline & _
> " </form>" & vbNewline
>end if
>'--------------- End of Code Snippet --------------------------------
>
>On Wed, 11 Aug 2004 17:35:18 -0400, "Paul Baker [MVP, Windows - SDK]"
><paulb@online.rochester.rr.com> wrote:
>
>>That's an interesting question. However, it is only the dynamic parts of the
>>HTML that you need to worry about.
>>
>>The rest of it, you can put in the ASP as is simply by closing the brackets.
>>
>>eg.
>>
>><%
>> whatever = ...
>> Response.Write(whatever)
>>%>
>><form>
>> blah blah blah
>></form>
>><%
>> ...
>>%>
>>
>>You can also use =expression as shorthand for writing an expression if it is
>>the entire code within brackets.
>>
>>For example <%=whatever%> instead of <%Response.Write(whatever)%>
>>
>>Does that help?
>>
>>Paul
>>
>>"TinyTim" <TinyTim@MissVicky.com> wrote in message
>>news:ar3lh0p2eh98lcgtn3opaar8b0uv5j8bpi@4ax.com...
>>> I'm a newbie at ASP & HTML. It seems that when you use server side
>>> code and you're going to return a customized HTML form with several
>>> fields and labels, you have to do an extensive amount of
>>> Response.Writes.
>>>
>>> Are there any tools that will let you design the form then convert
>>> that form to Response.Writes that you can further customize with ASP
>>> logic? For instance: use Dreamweaver to design the form, then another
>>> program to convert to response.writes in an aspx file.
>>>
>>> What's the easy way of doing it? Just trying to make it less
>>> laborious for me.
>>>
>>> Response.Write "Thanks,"
>>>
>>> tt
>>>
>>
- Next message: mark | r: "OT - XP SP2"
- Previous message: Evertjan.: "Re: return single value in asp/sql"
- In reply to: TinyTim: "Re: Lots of Response.Writes of HTML - How do YOU do it?"
- Next in thread: TinyTim: "Re: Lots of Response.Writes of HTML - How do YOU do it?"
- Reply: TinyTim: "Re: Lots of Response.Writes of HTML - How do YOU do it?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|