|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
Multiple lines with one command
Hi all
I gotta ask this, since I'm in a dispute with my ASP teacher. We are writing small ASP scripts, you know trying to learn it but the way we write ASP is pretty complicated for me. Here is a simple example of our scritps: Code:
<%
Language = VBScript
Dim strEtunimi
Response.Expires = 0
If Request.ServerVariables("QUERY_STRING") <> "" Then
strEtunimi = Request.QueryString("etunimi")
response.write "Your name is <b>" & strEtunimi & "</b>"
%>
<% Else %>
<html>
<body>
Personal data:
<form name="formis" method="get" action="vastaus_v2.asp">
Etunimi: <input type="text" name="etunimi" value="">
<p>
<input type="submit" value="Lähetä">
<input type="reset" value="Tyhjennä">
</form>
</body>
</html>
<% End If %>
What bothers me is the multiple opening and closing ASP tags on the document. With PHP I've got used to the idea that I can put everything inside one set of PHP tags. In this example both the Else and the End If are enclosed in their own ASP tags and that freaks me out (I like details). I can only imagine how this looks if we would be writing a much more complex and bigger application. What I'd like is to enclose all of this inside one set of ASP tags and have Response.Write print all the necessery HTML code. Is this possible?
__________________
-- Tomi Kaistila -- Developer's Journal The more you learn, the more you know. The more you know, the more you forget. The more you forget, the less you know. |
|
#2
|
|||
|
|||
|
Of course you can put your whole page in respnse.write tags if you wish. But believe it or not Interleaved code is faster than all response.write statements. (See this article: http://www.4guysfromrolla.com/webtech/021302-1.shtml) I think PHP lends itself a little bit better to limiting the code to one set of <? ?> tags. Since your strings can wrap multiple lines as long as you end it with a ; when you are done. And the ability to write variables without having to concatentate strings. stuff like that. Plus, echo is much easier to write then response.write. I had half a mind to write a sub in asp:
PHP Code:
but i thought that would piss off anyone else that needed to modify my code in the future. |
|
#3
|
|||
|
|||
|
Sure you could have response.write print out all of your html, but I think that may be more difficult to read and trouble shoot HTML issues. But you could do something like this. The only issue is that when you have something in double quotes you need to either use 3 quotes (I think), or use single quotes. This is why I just try to avoid that issue and just just have multipul <% %> tags.
Code:
<%
Language = VBScript
Dim strEtunimi
Response.Expires = 0
If Request.ServerVariables("QUERY_STRING") <> "" Then
strEtunimi = Request.QueryString("etunimi")
response.write "Your name is <b>" & strEtunimi & "</b>"
Else
response.write "<html>"
response.write "<body>"
response.write "Personal data:"
response.write "<form name='formis' method='get' action='vastaus_v2.asp'>"
response.write "Etunimi: <input type="""text""" name="""etunimi""" value=""">"
response.write "<p>"
...
response.write "</body>"
response.write "</html>"
End If
%>
|
|
#4
|
|||
|
|||
|
when i do use long response.write statements then you can always use the underscore to continute lines:
PHP Code:
of course that will show in html as <html><head><title>HI there</title></head> unless of course you do this. PHP Code:
I'll also do my sql statements like this for readablity: PHP Code:
|
|
#5
|
||||
|
||||
|
Thank you for such speady replies. They were really helpful. Rewritten code of the example script would look something like this:
Code:
<%
Language = VBScript
Dim strEtunimi
Response.Expires = 0
If Request.ServerVariables("QUERY_STRING") <> "" Then
strEtunimi = Request.QueryString("etunimi")
response.write "Etunimesi on <b>" & strEtunimi & "</b>"
Else
response.write "<html>" & _
"<body>" & vbcrlf & _
"Henkilötietojen syöttäminen:" & vbcrlf & _
"<form name='formis' method='get' action='vastaus_v2.asp'>" & vbcrlf & _
"Etunimi: <input type='text' name='etunimi' value=''>" & vbcrlf & _
"<p>" & vbcrlf & _
"<input type='submit' value='Lähetä'> " & vbcrlf & _
"<input type='reset' value='Tyhjennä'>" & vbcrlf & _
"</form>" & vbcrlf & _
"</body>" & vbcrlf & _
"</html>"
End If
%>
Much more compact in my opinion and more simple to write more complicated applications, though a little clumsy with all the quotes and underscores but I got what I wanted ![]() Thanks again for the advices. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Multiple lines with one command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|