For Programmers: Free Programming Magazines  


Home > Archive > ASP > August 2007 > tutorial help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author tutorial help
jp2code

2007-08-07, 6:56 pm

Referring to this page:
http://msconline.maconstate.edu/tut...03/asp03-06.asp

The "logon.asp" file writes "Incorrect Password" to Message.

Later, in the html body, the tutorial tries to access this string using
<%=Msg%>

Questions about this:

Q1. Doesn't Message have to be declared?

Q2. How and where should Message be declared so that it is guaranteed to be
available later in the html?

Q3. Is <%=Msg%> a typo? Msg is not the same as Message, is it? Shouldn't it
be <%=Message%>?

Q4. If I want to look up the syntax of writing ASP, what language would I
look under? Is it equivalent to VB6?

Thanks,
~Joe


Bob Barrows [MVP]

2007-08-07, 6:56 pm

jp2code wrote:
> Referring to this page:
> http://msconline.maconstate.edu/tut...03/asp03-06.asp
>
> The "logon.asp" file writes "Incorrect Password" to Message.
>
> Later, in the html body, the tutorial tries to access this string
> using <%=Msg%>
>
> Questions about this:
>
> Q1. Doesn't Message have to be declared?


Variables only have to be declared if the Option Explicit directive
appears at the beginning of the script.
>
> Q2. How and where should Message be declared so that it is guaranteed
> to be available later in the html?


Message is a server-side variable. It will never be available to the
html. Server-side code generates html - that's pretty much all it does.
Once the html is sent to the client, the server-side code, including
variables, is out of of the picture.

The only way to pass the value of a server-side variable to the html is
to write it to Response, as this code does. If you have client-side code
and you want to have a client-side variable that contains the value of
the server-side variable, again, the value needs to be written to
Response, like this:

<html>
<script type="text/javascript">
var Message="<%=Message%>"
alert(Message)
</script>

In vbscript, variables can be declared anywhere in the script block.
When compiled, the variable declarations are "hoisted" to the beginning
of the script block.
Experienced developers tend to declare their variables at the beginning
of the script.

>
> Q3. Is <%=Msg%> a typo? Msg is not the same as Message, is it?
> Shouldn't it be <%=Message%>?

Yes, it's a typo. Without Option Explicit, you will not get an error:
just nothing written into the html.

>
> Q4. If I want to look up the syntax of writing ASP, what language
> would I look under? Is it equivalent to VB6?
>

ASP is not a language. It is a "platform" that allows the use of several
scripting languages. Most examples are written in vbscript, but there
are those who swear by using javascript.

http://msdn2.microsoft.com/en-us/library/ms675532.aspx

http://www.microsoft.com/downloads/...&DisplayLang=en

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Dave Anderson

2007-08-07, 6:56 pm

"jp2code" wrote:
> Q1. Doesn't Message have to be declared?


Not unless [Option Explicit] is declared:
http://msdn2.microsoft.com/en-us/library/bw9t3484.aspx



> Q2. How and where should Message be declared so that it is
> guaranteed to be available later in the html?


Oddly enough, your variables can be declared anywhere in the script that has
the same scope. You can even declare them after you use them.
http://blogs.msdn.com/ericlippert/a.../18/159378.aspx


> Q3. Is <%=Msg%> a typo? Msg is not the same as Message, is it?
> Shouldn't it be <%=Message%>?


Your understanding of the problem is correct.


> Q4. If I want to look up the syntax of writing ASP, what language
> would I look under? Is it equivalent to VB6?


ASP can be written in any number of languages. By default, IIS supports
JScript and VBScript.

JScript: http://msdn2.microsoft.com/en-us/library/yek4tbz0.aspx
vbscript : http://msdn2.microsoft.com/en-us/library/d1wf56tt.aspx
ASP: http://msdn2.microsoft.com/en-us/library/ms524716.aspx


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Evertjan.

2007-08-07, 6:56 pm

jp2code wrote on 07 aug 2007 in microsoft.public.inetserver.asp.general:

> Referring to this page:
> http://msconline.maconstate.edu/tut...03/asp03-06.asp
>
> The "logon.asp" file writes "Incorrect Password" to Message.
>
> Later, in the html body, the tutorial tries to access this string
> using <%=Msg%>
>
> Questions about this:
>
> Q1. Doesn't Message have to be declared?
>
> Q2. How and where should Message be declared so that it is guaranteed
> to be available later in the html?
>
> Q3. Is <%=Msg%> a typo? Msg is not the same as Message, is it?
> Shouldn't it be <%=Message%>?
>
> Q4. If I want to look up the syntax of writing ASP, what language
> would I look under? Is it equivalent to VB6?


You are completely right. The code is terrible:


========================================
=============
> <%
> If Request.Form("SubmitButton") = "Submit" Then
>
> If Request.Form("Password") = "xyzzy" Then


So there is no test if "Account" is correct

> Response.Redirect("welcome.asp")
> Else


The else is nonsense, since the redirect has already taken away the other
possibility

> Message = "Incorrect Password"


Should be Msg = ...
Also: the first pass the variable msg is undeclared!!!!

> End If
>
> End If
> %>
>

[..]
> <span style="color:red"> <%=Msg%> </span>


The spaces around the <%%> are useless, methinks.

========================================
===============

I would suggest this:

===================================
<% ' vbscript [in examples always name the asp language used]

Option Explicit ' if you are inclined to such things
Dim Msg ' if you are inclined to such things

If Request.Form("Account") = "myName" AND_
Request.Form("Password") = "xyzzy" Then
Response.Redirect("welcome.asp")
End If

Msg = ""
If Request.Form("SubmitButton") = "Submit" Then
Msg = "<span style='color:red;'>Incorrect Password</span><br>"
End If

%>

<html>
<body>
<h3>Logon Page</h3>

<form action="logon.asp" method="post">
Account: <input type="text" name="Account" size="10">
<br>Password: <input type="password" name="Password" size="10">
<br><%=Msg%><input type="submit" name="SubmitButton" value="Submit">
</form>

</body>
</html>
===================================




--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com