Be the first to write a review
Pure ASP Upload 3 Review by James Threadgill, Part 2
In this tutorial we will look at how to use multiple image handling
If you’ve been following this tutorial series you already know I’m a big fan of DMXzone´s Pure ASP Upload 3. It’s a great tool, but I wanted more. I soon learned that if I wanted to get the most out of Dreamweaver---and tools like Pure ASP Upload 3, I would have fine tune the code generated by Dreamweaver and PU3 to expand the possibilities. I quickly found that with a little hand coding, I could develop web applications as powerful, feature packed, and as versatile as anything I could code by hand. And I could do it in a lot less time.
Toggling the Skip Empty Fields Feature
If you've read the first tutorial, this will be familiar. This time, however, we will be toggling multiple fields. First we need to apply the Dreamweaver update server behaviour and Pure ASP Upload. Next we apply the Pure ASP Upload 3.0 behaviour, and finally we're ready to customize the code. I'll try to keep the recap as brief as possible so those of you who have read the first tutorial don't spend too much time in familiar territory. At the same time, I will do my best to bring those who haven't read the first tutorial up to speed.
In the first tutorial I had readers switch to code view before they save the page after applying the pure upload behaviour. This is because pure ASP upload must modify the Dreamweaver update server behaviour. It uses the generic Request() Collection and the Request.Form() collection which cannot be used after calling a binary upload. Instead pure ASP upload uses UploadFormRequest() to get the necessary values.
Tip: The generic Request() and the Request.Form() collections cannot be called after calling a binary upload.
You should notice the update parameter or your image fields has changed. Pure ASP upload uses the MM_IIF to implement for the skip empty fields feature. As you may recall the MM_IIF enough returns one of two values true or false to identify empty fields. This is the heart of the skip empty fields feature. Basically, the image field parameters use the image form field value if an image has been selected. Otherwise, it uses the hidden field upload_org_yourimagefieldname created by the Pure ASP Upload extension. This contains the original image field value which is substituted for the empty upload form field, thus skipping the empty field. These are the parameters we going to use to toggle the skip empty fields feature. We do this by creating two parameters: one which skips the empty field using the MM_IIF and one that does not skip the empty field using the original Dreamweaver created parameter modified for upload. With an if… then… else statement and the "Delete Image?" check boxes as switches, we can control the input.
Tip: You'll find the MM_IIF implementation in the code block immediately above the Dreamweaver update server behaviour.
Now that we know what we are going to do, let's get to it. The modified Dreamweaver update server behaviour appears in the code block below. In this case the name of my image fields is named P_Image(i) where i is an integer. You should notice that my image fields are named in a numeric sequence. This becomes useful when we delete the images. I've commented the code before and after each of the toggle sections so you can easily identify them.
<%
If (CStr(UploadFormRequest("MM_update")) = "UpdateForm") Then
If (Not MM_abortEdit) Then
' execute the update
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_datasource_STRING
MM_editCmd.CommandText = "UPDATE About SET P_Heading1 = ?, P_Image1
= ?, P_Paragraph1 = ?, P_Heading2 = ?, P_Image2 = ?, P_Paragraph2 = ?,
P_Heading3 = ?, P_Image3 = ?, P_Paragraph3 = ? WHERE P_ID = ?"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1",
202, 1, 50, UploadFormRequest("P_Heading1")) ' adVarWChar
'Toggle skip empty field behavior to remove existing image
If CStr(UploadFormRequest("Delete_Image1")) <> ""
Then
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2",
202, 1, 100, UploadFormRequest("P_Image1")) ' adVarWChar
Else
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2",
202, 1, 100, MM_IIF(UploadFormRequest("P_Image1"), UploadFormRequest("P_Image1"),
UploadFormRequest("upload_org_P_Image1"))) ' adVarWChar
End If
'End toggle
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3",
203, 1, 536870910, UploadFormRequest("P_Paragraph1")) ' adLongVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4",
202, 1, 50, UploadFormRequest("P_Heading2")) ' adVarWChar
'Toggle skip empty field behavior to remove existing image
If CStr(UploadFormRequest("Delete_Image2")) <> ""
Then
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param5", 202, 1, 100, UploadFormRequest("P_Image2"))
' adVarWChar
Else
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5",
202, 1, 100, MM_IIF(UploadFormRequest("P_Image2"), UploadFormRequest("P_Image2"),
UploadFormRequest("upload_org_P_Image2"))) ' adVarWChar
End If
'End toggle
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6",
203, 1, 536870910, UploadFormRequest("P_Paragraph2")) ' adLongVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7",
202, 1, 50, UploadFormRequest("P_Heading3")) ' adVarWChar
'Toggle skip empty field behavior to remove existing image
If CStr(UploadFormRequest("Delete_Image2")) <> ""
Then
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8",
202, 1, 50, UploadFormRequest("P_Image3")) ' adVarWChar
Else
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8",
202, 1, 50, MM_IIF(UploadFormRequest("P_Image3"), UploadFormRequest("P_Image3"),
UploadFormRequest("upload_org_P_Image3"))) ' adVarWChar
End If
'End toggle
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9",
203, 1, 536870910, UploadFormRequest("P_Paragraph3")) ' adLongVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10",
5, 1, -1, MM_IIF(UploadFormRequest("MM_recordId"), UploadFormRequest("MM_recordId"),
null)) ' adDouble
The line of code after the Then uses the Dreamweaver generated parameter code modified for upload. It does not use the MM_IIF implementation and does not skip the empty field. The line of code after the Else uses the parameter as modified by the pure ASP upload extension with the MM implementation and skips the empty field, using the value from the hidden field upload_org_P_Imagei), which as you recall holds the value of the original image. Now all we have to do is close the If… Then… Else I statement with the final End If and repeat the process for each image field.
Tip: The parameters both have the same name: param3 in the example. This is because only one parameter is used in the SQL statement depending upon the condition of the Delete Image? check box.
Now that we set up the code to toggle the skip empty fields feature all we have to do is handle the image delete's.
James Threadgill
James Threadgill has authored numerous tutorials on ASP and ASP.NET web development, published on such sites as the Dynamic Zones and MSDN Accademic Alliance. He co-authored the Sam's book Dreamweaver MX: ASP.NET Web Development.
James first began computer programming in 1995 while attending Alvin Community College. He completed a certificate of computer science program and an Associate of Arts degree at Alvin before going on to the University of Houston-Clear Lake where he was awarded a Bachelor of Science and a Master of Arts.
James publishes fiction, poetry, and visual arts under the name Wayne James. His fiction first appeared in Raconteur in 1995 and since has been published numerous times: in Hadrosaur Tales 5 and 7, Bayousphere, and in the Write Gallery e-zine. His poetry first appeared in the small press magazine Lucidity in 1996 and has been published numerous times since. His collection of fiction and poetry, When Only the Moon Rages, was released in 2000. Most recently his work appeared in Tales of the Talisman winter 2010 and spring 2011 issues. James currently attends graduate school at the University of Houston and owns and operates small web design and internet marketing firm, WWWeb Concepts, with his wife, Karen, in Houston, TX USA.