欢迎光临
我们一直在努力

ASP常见问题及解答(5)-ASP教程,ASP技巧

建站超值云服务器,限时71元/月

1.功能: 过虑html字符

输入:字符串

输出:经格式化后的字符串

function htmlencode(fstring)

if not isnull(fstring) then

fstring = replace(fstring, ">", ">")

fstring = replace(fstring, "<", "&lt;")

fstring = replace(fstring, chr(32)&chr(32), "&nbsp;&nbsp;")

fstring = replace(fstring, chr(9), "&nbsp;")

fstring = replace(fstring, chr(34), "&quot;")

fstring = replace(fstring, chr(39), "&#39;")

fstring = replace(fstring, chr(13), "")

fstring = replace(fstring, chr(10) & chr(10), "</p><p> ")

fstring = replace(fstring, chr(10), "<br> ")

htmlencode = fstring

end if

end function

2.分页类

参数:系统(如:product,article),条件(如果是数值,则默认为categoryid的值),排序,

每页显示记录数,模式(more:显示更多字样,page:显示翻页导航),

翻页导航模式(number:显示数字,page:显示上一页,下一页),记录显示模版名(显示记录的过程名)

class list

dim p_system 系统表,如tblproduct,tblarticle

dim p_where 条件

dim p_orderby 排序

dim p_recordcount 每页显示记录数

dim p_horizontal 每行显示记录数

dim p_mode 列表模式,参数:more(更多模式,显示更多字样),page(列表模式,显示翻页导航)

dim p_moreurl 更多模式时的url

dim p_paginationmode 翻页导航模式,参数:number(数字导航,显示如:1,2,3,4),page(翻页导航,显示如:上一页,下一页)

dim p_models 列表模版过程

dim p_table 列表的table标签

dim p_page 页码

dim p_member 是否显示会员产品

dim p_groupwhere

private sub class_initialize

p_system=""

p_where=""

p_orderby=" order by categoryid,orderby,postdate"

p_recordcount=15

p_horizontal=4

p_mode=""

p_moreurl=""

p_paginationmode="page"

p_models=""

p_table="<table width=100% border=0 align=center cellpadding=0 cellspacing=0 bordercolor=#cccccc style=border-collapse: collapse>"

p_page=1

p_member=false

p_groupwhere="groupid=0"

end sub

property let system(value)

p_system=value

end property

property let where(value)

if isint(value) then

p_where=" where categoryid="&value

else

p_where=" where ("&value&")"

end if

end property

property let orderby(value)

p_orderby=" order by "&value

end property

property let recordcount(value)

p_recordcount=value

end property

property let horizontal(value)

p_horizontal=value

end property

property let mode(value)

p_mode=value

end property

property let moreurl(value)

p_moreurl=value

end property

property let paginationmode(value)

p_paginationmode=value

end property

property let models(value)

p_models=value

end property

property let table(value)

p_table=value

end property

property let page(value)

if getnumeric(value)<1 then

p_page=1

else

p_page=int(value)

end if

end property

property let member(value)

p_member=value

if p_member then

authorizationid=getvalue("tblmember","authorizationid","memberid="&session("memberid"))

if authorizationid="" or authorizationid=0 then

authorizationid=getvalue("tblgroup","authorizationid","groupid="&session("groupid"))

end if

virtual=getvalue("tblauthorization","virtual","authorizationid="&authorizationid)

autharr=split(virtual,",")

for i=0 to ubound(autharr)

if i=0 then

p_groupwhere="groupid="&getvalue("tblgroup","groupid","authorizationid="&autharr(i))

else

p_groupwhere=p_groupwhere&" or groupid="&getvalue("tblgroup","groupid","authorizationid="&autharr(i))

end if

next

else

p_groupwhere="groupid=0"

end if

end property

列表过程

public sub list()

dim rs

dim where

if p_where="" then

where=" where "&p_groupwhere&" and publish=1"

else

where=p_where&" and ("&p_groupwhere&") and publish=1"

end if

strsql="select * from "&p_system&where&p_orderby

response.write strsql

response.end

set rs=getrecord(strsql)

if rs.eof then

response.write convertencode(lgenorecord,gb,language)

exit sub

end if

rs.pagesize=p_recordcount

if rs.pagecount<p_page then p_page=rs.pagecount

rs.absolutepage=p_page

dim ii

response.write p_table

for i=1 to p_recordcount

if rs.eof then

exit for

end if

response.write "<tr>"

for ih=0 to p_horizontal

if ii=p_recordcount then

exit for

end if

if rs.eof then

response.write "<td width=" & 1/(p_horizontal+1)*100 & "% >&nbsp;</td>"

else

response.write "<td width=" & 1/(p_horizontal+1)*100 & "% >"

execute "call " & p_models

response.write "</td>"

rs.movenext

end if

ii=ii+1

next

response.write "</tr>"

next

response.write "</table>"

if p_mode="more" then

response.write "<div align=right>"&p_moreurl&"</div>"

end if

if p_mode="page" then

response.write "<table width=100% border=0 cellspacing=0 cellpadding=3><tr><td align=right>"

call pagination(p_page,rs.recordcount,rs.pagecount,p_paginationmode)

response.write "</td></tr></table>"

end if

end sub

end class

——————————-列表过程结束————————————————————-

3.如何在客户端无刷新调用服务端代码

1.<iframe src="ifm.asp?param=??"></iframe>

2.xmlhttp:

dim objxmlhttp

set objxmlhttp=createobject("microsoft.xmlhttp")

objxmlhttp.open "get","xmlhttp.asp",false

参数1:post,get;参数2:请求的url, 参数3:同步或异步调用

objxmlhttp.send ""

magbox objxmlhttp.responsetext 服务端输出到客户端的文本数据

————

xmlhttp:参考

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmobjxmlhttprequest.asp

4.<%

取得地址栏完整地址

function geturl()

on error resume next

dim strtemp

if lcase(request.servervariables("https")) = "off" then

strtemp = "http://"

else

strtemp = "https://"

end if

strtemp = strtemp & request.servervariables("server_name")

if request.servervariables("server_port") <> 80 then strtemp = strtemp & ":" & request.servervariables("server_port")

strtemp = strtemp & request.servervariables("url")

strtemp=left(strtemp,instrrev(strtemp,"/"))

geturl = strtemp

end function

response.write geturl()

%>

5.分页类

<%

===========================================================

分页类,大体思想由.net的datagrid的使用方式而来

功能:自动生成datagrid列表头和内容,以及分页栏

根据网友bubuy (澎湃 nomoneytobuy)得分页函数修改成类

使用示例:

dim dg

dim url

dim fld(2)

dim fldname(2)

dim fldwidth(2)

fld(0) = "id"

fld(1) = "title"

fld(2) = "input_date"

fldname(0) = "编号"

fldname(1) = "标题"

fldname(2) = "录入日期"

fldwidth(0) = "10%"

fldwidth(1) = "60%"

fldwidth(2) = "30%"

set dg = new datagrid

dg.datasource = rs_grid

dg.titlecolor = "#dce19d"

dg.pagesize = 1

dg.fields = fld

dg.fieldsname = fldname

dg.fieldwidth = fldwidth

url = request.servervariables("url") & "?param=testparameter" 存在原有参数的情况

dg.url = url

dg.generate()

=============designed by windancer 2003.10.17===============

class datagrid

private obj_recordset recordset

private int_pagesize 每页纪录数

两个数组保存数据库字段名和中文名称

private arr_field 数据库字段

private arr_fieldname 字段显示名称()

private arr_fieldwidth 字段显示宽度

private str_titlecolor 表头颜色#efffce

private str_url 请求的url

private str_error 出错信息

private sub class_initialize()

int_pagesize = 10

str_titlecolor = "#ffffff"

str_error = ""

end sub

===============================================================

属性信息

================================================================

———————————–

数据源,暂时只支持recordset

———————————–

public property let datasource(obj)

set obj_recordset = obj

end property

public property let pagesize(intvalue)

int_pagesize = intvalue

end property

public property get pagesize

pagesize= int_categoryid

end property

public property let fields(arr)

arr_field = arr

end property

public property get fields

fields= arr_field

end property

public property let fieldsname(arr)

arr_fieldname = arr

end property

public property get fieldsname

fieldsname= arr_fieldname

end property

public property let fieldwidth(arr)

arr_fieldwidth = arr

end property

public property get fieldwidth

fieldwidth= arr_fieldwidth

end property

public property let titlecolor(strvalue)

str_titlecolor = strvalue

end property

public property get titlecolor

titlecolor= str_titlecolor

end property

—————————————————–

这个属性是为了保存url路径

如果当前路径带有参数,那么就用&page=x,否则就用?page=x

——————————————————

public property let url(strvalue)

str_url = strvalue

end property

public property get url

url= str_url

end property

================================================================

方法

================================================================

—————————————————————-

显示当前错误

—————————————————————-

private sub showlasterror()

response.write(str_error)

response.end()

end sub

—————————————————————-

generate()

利用ado分页

—————————————————————–

public sub generate()

—-检查参数————————–

check

———变量声明———————————–

dim fieldcount 显示字段

fieldcount = ubound(arr_field) + 1

dim currentpage 当前页

dim pgcount 总页数

dim reccount 记录数,本来用rs.recordcount可以取到,保存下来效率会比较高

dim hasotherparam url是否包含其他参数

dim pageparam 当前分页url参数

dim pageinfomation 当前分页状态信息

dim seperator 设置分隔符

seperator = "&nbsp;&nbsp;"

————-处理url参数—————————

if instr(str_url,"?")>0 then

hasotherparam = true

pageparam = "&page="

else

hasotherparam = false

pageparam = "?page="

end if

———-获取当前页——————————–

currentpage = request.querystring("page")

if currentpage="" then

currentpage=1

else

currentpage=cint(currentpage)

end if

———–处理数据源——————————

obj_recordset.pagesize = int_pagesize

reccount = obj_recordset.recordcount

pgcount = obj_recordset.pagecount

if obj_recordset.eof then

response.write("<center><font stlye=font-size:14px; color=#ff0000>对不起,没有记录!</font></center>")

else

———–处理ado分页—————————-

if currentpage < 1 then

currentpage = 1

else

if currentpage>pgcount then

currentpage = pgcount

end if

end if

obj_recordset.absolutepage = currentpage

response.write("<table width=100% border=0 cellpadding=0 cellspacing=0 style=font-size:12px;>")

—————翻页链接—————————–

dim firstlink,prevlink,nextlink,lastlink 定义向上和向下翻的变量

———————–首页————————-

if currentpage>1 then

firstlink = "<a href=" & url & pageparam & "1>首页</a>"

prevlink = "<a href=" & url & pageparam & cstr(currentpage-1) & ">上一页</a>"

else

firstlink = "首页"

prevlink = "上一页"

end if

————下一页—————-

if currentpage<pgcount then

nextlink = "<a href=" & url & pageparam & cstr(currentpage+1) & ">下一页</a>"

lastlink = "<a href=" & url & pageparam & pgcount & ">尾页</a>"

else

nextlink = "下一页"

lastlink = "尾页"

end if

pageinfomation = firstlink & seperator & prevlink & seperator & nextlink & seperator & lastlink & seperator & "每页" & cstr(int_pagesize) & "条记录" & seperator & "共" & pgcount & "页" & seperator & "目前第" & currentpage & "页" & seperator

response.write("<tr><td align=center>")

response.write("<table width=100% border=1 cellpadding=2 cellspacing=2 bordercolor=#999999>")

—————设置表头—————–

response.write("<tr bgcolor=" & str_titlecolor & ">")

dim i

for i=0 to fieldcount -1

response.write("<td align=center width=" & arr_fieldwidth(i) & "><font style=font-size:14px;><b>" & arr_fieldname(i) & "</b></font></td>")

next

response.write("</tr>")

———————输出内容———————————

i=0

while (not obj_recordset.eof) and i<int_pagesize

dim cursor

response.write("<tr>")

for cursor = 0 to fieldcount -1

response.write("<td align=center>" & obj_recordset(arr_field(cursor)) & "</td>")

next

response.write("</tr>")

i=i+1

obj_recordset.movenext

wend

————————输出分页条————————————

response.write("<tr><td align=right colspan=" & cstr(fieldcount) & ">" & pageinfomation & "</td></tr>")

response.write("</table></td></tr></table>")

end if

end sub

———-检查参数是否正确—————

private sub check()

if ubound(arr_field)<>ubound(arr_fieldname) then

str_error="fields数组和fieldname数组维数必须相同"

end if

if obj_recordset=empty then

str_error="数据源不能为空,请设置datasource属性"

end if

if int_pagesize="" then

str_error="数据源不能为空"

end if

showlasterror

end sub

end class

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP常见问题及解答(5)-ASP教程,ASP技巧
分享到: 更多 (0)

相关推荐

  • 暂无文章