Dreamweaver Ultradev creates a static page of the news system 2

Source: Internet
Author: User
Tags insert dreamweaver
dreamweaver| Static | News system

1, the template modification. We start with a simple template modification, the principle is very simple: the template data records out, using the Updata record, on the line. We put a form and a text field (multiple lines) on the example_updata.asp page and set up a Recordset, as shown in the following figure:

<%= The Record (RsUpdata.Fields.Item ("E_meno"). Value)%> inserts into your text field, and then executes (Server bahaviors---> Updata record) and points the success page to ok.htm.

2, the news record and the deletion of the page. Common record Deletion I believe everyone will, but if we delete the records in the database, the hard disk still has a static page of the file, which we do not want to see, so we have to use the FSO DeleteFile method.

Open the Browse.asp page we just made, in the 2nd column of the table, add a form field, 1 buttons and 2 hidden fields (name N_filepath and Id_news) to set the action= "del.asp" of the form. Effect as shown:

Records <%= (RsBrowse.Fields.Item ("N_filepath") respectively. Value)%> and <%= (RsBrowse.Fields.Item ("Id_news"). Value)%> inserted into the hidden domain N_filepath and Id_news's value, this page is OK.

3, delete the news page del.asp. On this page we use command and FSO respectively to delete records and *.htm pages, open a blank del.asp page, open the date Bindings--> command (Stored Procedure), and create a new command command, as shown in:

OK, delete the database record is done Oh! Is it super simple! Now let's add the FSO code to delete the news *.htm page.

Locate the following code:

<%

Set comdelnews = Server.CreateObject ("Adodb.command")
Comdelnews.activeconnection = mm_asp2htm_string
Comdelnews.commandtext = "DELETE from t_news WHERE id_news =" + Replace (Comdelnews__varid, "'", "" ") +" "
Comdelnews.commandtype = 1
Comdelnews.commandtimeout = 0
Comdelnews.prepared = True
Comdelnews.execute ()

%>
Here are the command commands we just added, and add the following code below this code:

<% ' Delete news static page
Dim filepath
Filepath=request ("N_filepath")
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. DeleteFile (Server.MapPath (filepath))
Set FSO = Nothing

Response.Redirect "ok.htm" ' Operation successfully turned to page
%>

This static page Delete work is also done, save!

 
PS: Why should the FSO's code be placed under command commands? This is just in case of running del.asp page, there are unexpected events, such as: power outages, crashes, may be above command commands have been executed, then in the browsing time, or to delete the effect of the news, at least not shown. However, if the reverse, the first implementation of the FSO to remove the *.htm page, but the record of the database is still, users can not find the page when clicked browsing. This is a small problem, we can think more about it.

4, News modification update. About this function, update the content of the database methods we are very familiar with the Updata record behavior is good, here is how to update the contents of *.htm? In fact, a relatively simple way is: recreate a *.htm page, of course, the name and path of the page is to update the name and path of the news page, so that, after the creation of the original file, the updated operation is completed. Good! Understand the truth, also have the front to add the foundation of the news, it should be difficult not to pour you!
We first add a button on the Browse.asp page, after the previous "delete" button, insert a table column, insert a form inside, and a button and a hidden field name=id_news_updata (you can also use text such as: Update, Connect to the Updata.asp page with the parameter id_news=<%= (RsBrowse.Fields.Item ("Id_news"). Value), as shown in the%>:

Set the form (here is Form2) action= "updata.asp", OK, this page is OK, save!

5, updata.asp page. Here we first set up a Recordset, as shown in figure:

Then we insert the form used to update the record, similar to the add.asp page where the news is added, as shown in the following example:

Then, add a updata record behavior, and the success page points to ok.htm. All right, let's put it on this page first! Do the following first!

6, Save the updated updata_save.asp page. This page, in addition to adding news insert record behavior, updata_save.asp and save.asp page code should be the same, we can open save.asp page, save as updata_save.asp. OK, we open the Updata.asp page again, the following we have to split the code of the UD, with the previous experience, it should be no problem! Cut the following code:

<%
' * * * Edit operations:declare variables

MM_editAction = CStr (Request ("URL"))
If (Request.QueryString <> "") Then
MM_editAction = mm_editaction & "?" & Request.QueryString
End If

' Boolean to abort record edit
MM_abortEdit = False

......
......
..... Intermediate code skipped ...

Set MM_editCmd = Server.CreateObject ("Adodb.command")
Mm_editcmd.activeconnection = MM_editConnection
Mm_editcmd.commandtext = MM_editQuery
Mm_editcmd.execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect (MM_editRedirectUrl)
End If
End If

End If
%>

Then put the updata.asp form of the action= "updata_save.asp", Save!

Open updata_save.asp (This page is the one we saved from the save.asp page), we replace it with the updated code that we just cut out updata_ Save.asp page to add the record code (that is, the FSO code under those, forget, just look at the front), OK, save! This updated function also has, try! That's good!

So far, our asp2htm news system already has the essential function, the news addition, the deletion, the update also includes the template modification, but this is far from enough, we also need more humanized function, for instance: can create and select multiple templates, can customize and create news directory folder, And how we use the FSO properly in other places, and so on. There are a lot of program extensions waiting for us!

Previous Page Next Page 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.