Click to See Complete Forum and Search --> : Response.write
Sonia
03-05-2004, 06:44 AM
Just wanted to know if there is another way i can write the following code:
<%....
Else
Response.Write"<form method =post action = Updatedfile.asp><center>"
Response.Write"<table border =1>"
Response.Write"<tr><td colspan = 2 align = center bgcolor = black><b><font size = 5 color = white>UPDATE VALUES:<b></font></tr>"
Response.Write"<tr><td>Enter Roll Number: <td><input size = 25 name =rollnum value =" &x&"></tr>"
Response.Write"<tr><td>Enter First Name: <td><input size =25 name =first value = "& RS.Fields("FirstName") &"></tr>"
Response.Write"<tr><td colspan = 2 align = center><input type = submit value = ' Edit '></tr>"
Response.Write"</table></form>"
End If
%>
In another words, can I write that code without repeating the 'Response.Write' somuch of time.
Is there a way where I can write only 1 Response.Write and insert a block of tags withinn it.
athankon
03-05-2004, 08:38 AM
Make use of the concut symbol
i.e if you have 2 strings:
response.write "FIRST STRING"
response.write "SECOND STRING"
you can combine them as:
response.write "FIRST STRING"&"SECOND STRING"
buntine
03-06-2004, 05:47 AM
Its best to use ASP's with keyword aswell. I have demonstrated how to use it below.
with response
.Write"<form method=""post"" action= ""Updatedfile.asp""><center>"
.Write"<table border =1>" & vbCrLf & "<tr><td colspan=""2"" align=""center"" bgcolor=""black""><b><font size=""5"" color=""white"">UPDATE VALUES:<b></font></tr>"
.Write"<tr><td>Enter Roll Number: <td><input size=""25"" name=""rollnum"" value=""" & x & """></tr>"
.Write"<tr><td>Enter First Name: <td><input size=""25"" name=""first"" value=""" & RS.Fields("FirstName") & """></tr>"
.Write"<tr><td colspan=""2"" align=""center""><input type= ""submit"" value="" Edit ""></tr>"
end with
The with keyword is used is ASP when you want to focus on the properties of a particular object. Another example would be:
with response
with request
.write(.cookies("cookieName"))
.write(.serverVariables("SCRIPT_NAME"))
end with
end with
The preceding example shows how the with keyword allows us to simplify ASP's object handling methods.
You may have also noticed the vbCrLf which i placed in first portion of code. This will create a new-line in the output HTML source code which this script wil produce.
Finally, you should always use quotes around all parameter values when working with HTML. When using response.write(), we must use two double quotes in order to produce a single double quote in the output source. This is similar to C-style languages new-line escape sequence. (\n).
Regards,
Andrew Buntine.
simflex
03-06-2004, 07:33 AM
You can also try this method:
<%....
Else
%>
<form method =post action = Updatedfile.asp><center>
<table border =1>
<tr><td colspan = 2 align = center bgcolor = black><b><font size = 5 color = white>UPDATE VALUES:<b></font></tr>
<tr><td>Enter Roll Number: <td><input size = 25 name =rollnum value ="<%=rsStudents("x")%>"></tr>
<tr><td>Enter First Name: <td><input size =25 name =first value ="<%=rsStudents("FirstName") %>"></tr>
<tr><td colspan = 2 align = center><input type = submit value = ' Edit '></tr>
</table></form>
<%
End If
%>
I would try buntine's solution first because it is more elegant, more efficient, and less confusing but this is just to show that there many ways to skin a cat.