分享
 
 
 

ASP精华问题5

王朝asp·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

1.'功能: 过虑HTML字符

'输入:字符串

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

function HTMLEncode(fString)

if not isnull(fString) then

fString = replace(fString, ">", ">")

fString = replace(fString, "<", "<")

fString = Replace(fString, CHR(32)&CHR(32), " ")

fString = Replace(fString, CHR(9), " ")

fString = Replace(fString, CHR(34), """)

fString = Replace(fString, CHR(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 & "% > </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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有