Skills
Next:ASP Development 44 Skills Collection of the second
1. Several common functions
Round (pi, 2) rounded
FormatNumber (k,4) ' formats K as a number with four-bit decimal points.
eg. If K =20000 is shown as 20,000.00 if FormatNumber (k,0) is 20,000
Replace (Expression,find,replacewith) ' returns a string in which the specified substring has been replaced by another substring
Left (string,length) ' Returns a specified number of strings from the left-hand side of the string.
Split (expression[, delimiter[, count[, start]]] ' Returns a one-dimensional array based on 0 that contains the specified number of substrings.
eg. This split (String,[delimiter]) is used to divide strings using delimiter (characters used to identify substring bounds)
Instr (string1,string2) ' Returns the position of the first occurrence of a string in another string
Eg1. If InStr (addation, "Password Configuration table") <>0 Then ' description exists
EG2. If InStr (str, "AP") >0 a bad distinction between str = (AP,AP&AC), just change (' ap ', ' Ap&ac '), and then use InStr (STR, ' AP ')
2. pop-up window pick value
function PICKUPSP (Spdisid,pjnum,pdcode)
{
Window.opener.<%=theform%>. refnum<%=spid%>.value=spdisid;
Window.opener.<%=theform%>. lines<%=spid%>.value=pjnum;
window.opener.<%=theform%>.kokey<%=spid%>.value=pdcode;
Window.close ();
}
3. asp control picture display size (equal scaling)
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language= "JavaScript" >
<!--
var Flag=false;
function DrawImage (IMGD) {
var image=new image ();
IMAGE.SRC=IMGD.SRC;
if (image.width>0 && image.height>0) {
Flag=true;
if (image.width/image.height>= 164/112) {
if (image.width>164) {
imgd.width=164;
imgd.height= (image.height*164)/image.width;
}else{
Imgd.width=image.width;
Imgd.height=image.height;
}
imgd.alt=image.width+ "X" +image.height;
}
else{
if (image.height>112) {
imgd.height=112;
Imgd.width= (image.width*112)/image.height;
}else{
Imgd.width=image.width;
Imgd.height=image.height;
}
imgd.alt=image.width+ "X" +image.height;
}
}
}
-->
</script>
</HEAD>
<BODY>
<a href= "http://www.webjx.com/htmldata/2005-10-18/img.jpg" target= "_blank" ></a>
</BODY>
</HTML>
4. Operations on database tables (insert/update/delete) in ASP, using transaction processing and support for multiple transaction processing.
The
provides properties in the ASP's database object-linked object:
BeginTrans transaction start
CommitTrans transaction commit
RollbackTrans transaction rollback
<%
on Error Resume Next ' ERROR continues processing the
use transactions in ASP
Set conn=server.createobject ("ADODB. Connection ")
Conn. Open "Course_dsn", "Course_user", "Course_password"
Conn.begintrans ' start transaction
sql= ' delete from User_info '
Set RS =server.createobject ("Adodb.recordset")
Rs.Open sql,conn,3,3
If conn.errors.count>0 Then ' error occurred
Conn.rollbacktrans ' rollback
Set rs=nothing
conn.close
Set conn=nothing
Response.Write ' transaction failed and rolled back to the state before the modification! '
Response.End
Else
Conn.committrans ' Commit transaction
Set rs=nothing
conn.close
Set conn=nothing
Response.Write "Trading Success! The
Response.End
End If
%>
does not provide the ending of a transaction in ASP, BeginTrans only acts on its own domain, similar to a variable declaration, if it is begintrans in the function body, If the BeginTrans is in the page level outside the function body, the scope of the transaction starts from BeginTrans, and the end of the page is in the management state of the transaction.
5. Easysales Database Operations
Dim objcon,objrst,objsql
Dim CompanyID
Set Objcon = Server.CreateObject ("ADODB. Connection ")
Objcon.open Sysdns,sysname,syspassword
Set Objrst = Server.CreateObject ("ADODB. RecordSet ")
Objsql= "SELECT * from Passwordconfig where companyid= '" &session ("CompanyID") & ""
Objrst.open objsql,objcon,1,3
6. html format mail sent
HTML = "html = html & "html = html & "<title>sending cdonts Email Using html</title>"
html = html & "<link href=". /cn/new.css "rel=" stylesheet "type=" Text/css ">"
html = html & "html = html & "<body bgcolor=" "FFFFFF" ">"
html = html & "<p><font size=7>"
html = HTML & "This are a test mail in html<br>"
html = html & "Mail content here ...</font></p>"
html = html & "</body>"
html = html & "Dim strrecemail,strposemail,strsubject,strbody
Strrecemail=request ("email")
Strposemail= "yufh@alleasy.com.cn"
strsubject= "Information Download notification letter"
Strbody=html
7. Input is underlined
Style= "Border-right: #f7f7f7 0px solid; Border-top: #f7f7f7 0px solid; font-size:9pt; Border-left: #f7f7f7 0px solid; width:110px; Border-bottom: #c0c0c0 1px solid; height:16px; Background-color: #f7f7f7 "
8. Session & Cookies
Write a session:
session["username"] = "AA";
Session ("username") = "AA"
Read a Sessinn:
String username= session["username"];
Dim username=session ("username")
Cookies are roughly the same as this usage
9. The constant in several VB
The following constants are defined by the type library in Visual Basic for applications, and can be used to replace the actual value anywhere in the code:
Constant equals description
VbCrLf Chr + Chr (10) carriage return and newline character combination
vbcr CHR (13) return character
VBLF CHR (10) line feed
vbNewLine Chr + Chr (10) platform-specified new line character; for the current platform
vbNullChar Chr (0) a character with a value of 0
A string with a vbNullString value of 0 is used to invoke an external procedure, unlike a zero-length string ("")
vbObjectError-2147221504 the user-defined error number should be greater than this value, for example:
Err.Raise Number = vbObjectError + 1000
VbTab Chr (9) Tab.
Vbback CHR (8) BACKSPACE character
10. button is not available
<%if rsview.eof and Rsview.bof then%> ' There's a big problem here.
<input name= "Submit" type= ' Submit ' value= ' to the selected user to unlock ' disabled>
<%else%>
<input name= "Submit" type= ' Submit ' value= ' to the selected user unlock ' >
</td>
<%end if%>
One by one .
Error and return
if Rs.bof and rs.eof then '
There's still a problem.
Response.Write "<script Language=javascript>alert (' Can't find it! ');"
Response.Write "Javascript:history.go ( -1) </SCRIPT>"
End If
-----------------------------------
This is a jump.
<script language= "JavaScript" >
Alert (' <%=intOperationInfo%> ');
Window.navigate (' changepwd.asp ');
</Script>
A .
from
VBS
to the
JS
, mixed
<%
Dim checkpwdconfig
Checkpwdconfig=split (Addation, "/")
%>
<script language= "JavaScript" >
Alert ("<%=checkpwdconfig (0)%>")
</script>
A .
pop-up window
<script language=javascript>
function Openaddnew ()
{
Subwindow=window.open (".. /edit/passwordconfigedit.asp?method=new "," ', ' Scrollbars=yes,left=120,top=60,height=250,width=500,menubar=no, Location=no,toolbar=no,resizable=yes ', ' "
Subwindow.opener = this;
}
</script> call with a connection:
<a href= "" # "> Please modify password </a> picture call:
.gif ">
.
Paging
<!--#include file= "conn.asp"-->
<%
If Request ("PageNo") <> "then
Pageno=int (Request ("PageNo"))
Else
Pageno=1
End Ifsql= "SELECT * from news where [language]= ' Chinese ' and bigclassname= ' news ' ORDER by id DESC"
Set rs= Server.CreateObject ("ADODB.") Recordset ")
Rs.Open sql,conn,1,3
Rs.pagesize=20
If Rs.eof Then
Pageno=0
Else
Rs.absolutepage=pageno
End If
%>
==========================================
Total <%=rs.recordcount%>, <%=pageno%>/<%=int (rs.pagecount)%> page, per page <%=rs.pagesize%> bar
<a href= "Manage.asp?pageno=1" > Home </a>
<%if pageno>1 then%>
<a href= "Manage.asp?pageno=<%=int (pageno) -1%>" > Prev </a>
<%
End If
if int (pageno) <>int (Rs.pagecount) Then
%>
<a href= "Manage.asp?pageno=<%=int (pageno+1)%>" > next page </a>
<%end if%>
<a href= "Manage.asp?pageno=<%=int (rs.pagecount)%>" > End </a>
<%rs.close%>
<%call Closeconn ()
%>
.
Database UpdateSql= "SELECT * from [user] where username= '" &request ("username") & ""
Rs. Open sql,conn,1,3
RS ("Usermail") =request ("Usermail")
RS ("Userhome") =request ("Userhome"))
Rs.update
Rs.close
.
close a standalone window
<object id=closes type= "Application/x-oleobject" classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >< param name= "Command" value= "Close" >
</object>
<body>
<input type= "button" value= "Click my Close Window" >
</body>
A .
Very Fine table
<table border= "1" cellpadding= "0" cellspacing= 0 "width=" "height=" "bordercolorlight=" "#000000" bordercolordark= "#FFFFFF" >
<tr>
<td> </td>
</tr>
</table>
A .
several regular expressions
Require:/.+/,
Email:/^\w+ ([-+.] \w+) *@\w+ ([-.] \\w+) *\.\w+ ([-.] \w+) *$/,
Phone:/^ ((\d{3}\) | ( \d{3}\-))? (\ (0\d{2,3}\) |0\d{2,3}-)? [1-9]\d{6,7}$/,
Mobile:/^ ((\d{3}\) | ( \d{3}\-))? 13\d{9}$/,
URL:/^http:\/\/[a-za-z0-9]+\. [a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\ "\"]) *$/,
Idcard:/^\d{15} (\d{2}[a-za-z0-9])? $/,
Currency:/^\d+ (\.\d+)? $/,
Number:/^\d+$/,
Zip:/^[1-9]\d{5}$/,
QQ:/^[1-9]\d{4,8}$/,
Integer:/^[-\+]?\d+$/,
Double:/^[-\+]?\d+ (\.\d+)? $/,
中文版:/^[a-za-z]+$/,
Chinese:/^[\u0391-\uffe5]+$/,
UnSafe:/^ ([a-z]*|[ a-z]*|\d*| [-_\~!@#\$%\^&\*\.\ (\) \[\]\{\}<>\?\\\/\ ' \ "]*) |. {0,5}) $|\s/,
Left
Application (Control word count)
function title (str)
If Len (Trim (str)) >=28 Then
Title=left ((str), &)
Else
Title=trim (str)
End If
End Function
A .
judge the browser
<script language= "javascript1.2" >
<!--//
if (navigator.appname = ' Netscape ')
var language = Navigator.language;
Else
var language = Navigator.browserlanguage;
if (language.indexof (' en ') >-1) document.location.href = ' en/index.asp ';
else if (language.indexof (' en ') >-1) document.location.href = ' cn/index.asp ';
Else
Document.location.href = ' cn/index.asp ';
End-->
</script>