Back to Top
The nuts and bolts for
Creative web development

Pure ASP Upload 3 Review by James Threadgill

“In this tutorial we will look at how to take your image handling options to the limit”

DMXzone’s Pure ASP Upload is one of the best Tools I have for creating dynamic web sites. I’ve been using it over ten years. But there’s never really enough? Is there? Dreamweaver is a great tool for creating dynamic website, but if you want to get the most out of Dreamweaver and tools like DMXzone Pure ASP Upload, you have to reach under the hood and get your hands dirty by fine-tuning your code. With a little hand coding, however, there is no reason your applications cannot be as powerful and feature packed as any available.

Toggling the Skip Empty Fields Feature

Before we can toggle the empty fields feature, we need to apply the Dreamweaver update server behavior and Pure ASP Upload. Let's go ahead and do that now. But don't save the page yet.

Switch to code view and look at the Dreamweaver update server behavior code you'll notice that it's using the generic Request() Collection and the Request.Form() collection. Now save the page and as you do watch the code changes. You just saw the Pure ASP Upload modify the Dreamweaver server update server behavior for uploads. You'll notice that the generic Request() and Request.Form collections have been replaced with UploadFormRequest(). What you've just seen usually goes on behind-the-scenes. If you were paying close attention you may have noticed that the image field parameter code has also changed.

Tip: The generic Request() and the Request.Form() collections cannot be called after calling a binary upload.

The DMXzone Pure ASP Upload extension has implemented the MM_IIF for the skip empty fields feature. The MM_IIF enough returns one of two values true or false. A false value means the requested field is null or empty. A true value indicates that the requested field is not empty. If the MM_IIF returns false, the hidden field upload_org_image_field created by the Pure ASP Upload extension which contains the original image field value is substituted for the upload form field, thus skipping the empty field. This is the parameter we're going to use to toggle the skip empty fields feature. We're going to 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. Then we are placing them in an if… then… else statement and using the Delete Image? checkbox to toggle the feature and set the database image field value to null or skip the empty field when we wish.

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 behavior appears in the code block below. In this case the name of my image field is named Link_Image. You will notice I have added a blank space and a comment before and after our If… Then… Else… statement. Notice I've used the UploadFormRequest collection created by Pure ASP Upload to request the value of the Delete Image? checkbox. If the value is anything other than null, the code to reset the image field value to null is activated. Notice that if the user checks the Delete Image? checkbox and uploads a new image, the page still works properly and the image name value is updated in the database.

<%
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 Links SET Link_Title = ?, Link_URL = ?, Link_Image = ?, Link_Description = ? WHERE Link_ID = ?"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 203, 1, 536870910, UploadFormRequest("Link_Title")) ' adLongVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 203, 1, 536870910, UploadFormRequest("Link_URL")) ' adLongVarWChar
 
   'Toggle skip empty field behavior to remove existing image
   If CStr(UploadFormRequest("Delete_Image")) <> "" Then
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 203, 1, 536870910, UploadFormRequest("Link_Image")) ' adLongVarWChar
   Else    
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 203, 1, 536870910, MM_IIF(UploadFormRequest("Link_Image"), UploadFormRequest("Link_Image"), UploadFormRequest("upload_org_Link_Image"))) ' adLongVarWChar
   End If
  'End toggle
 
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 203, 1, 536870910, UploadFormRequest("Link_Description")) ' adLongVarWChar
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 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 a beat fields, instead using the value from the hidden field upload_org_Link_Image, 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.

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? checkbox.

Now that we have successfully toggled the skip empty fields feature. It's time to set up the image delete.

James Threadgill

James ThreadgillJames 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.

See All Postings From James Threadgill >>

Share this Article