龙卷风
关键字:asp,activex控件,数字签名,安全
我们来看看如何从服务端获取数据,传递到activex控件中。
1) 初始化时使用参数绑定
2) 运行时得到数据
打开vb6,新建activex控件工程。
工程名:focx,用户控件名:uc2
为了方便,我们使用activex控件接口向导…,菜单->外接程序->外接程序管理器->vb 6 activex控件接口向导。确定即可。
打开activex控件接口向导,下一步,对于可用名称和选定名称我们默认下一步,新建自定义成员,getinfo类型:属性,下一步,共有方法中选择我们刚才添加的getinfo,映射到控件选择txtinfo,成员选择text,下一步直到完成。代码窗口中会生成一些我们不需要的,删除,
注意!不要删除或修改下列被注释的行!
mappinginfo=txtinfo,txtinfo,-1,text
public property get getinfo() as string
getinfo = txtinfo.text
end property
public property let getinfo(byval new_getinfo as string)
txtinfo.text() = new_getinfo
propertychanged "getinfo"
end property
private sub command1_click()
label2.caption = getinfo()
end sub
从存贮器中加载属性值
private sub usercontrol_readproperties(propbag as propertybag)
txtinfo.text = propbag.readproperty("getinfo", "text1")
end sub
将属性值写到存储器
private sub usercontrol_writeproperties(propbag as propertybag)
call propbag.writeproperty("getinfo", txtinfo.text, "text1")
end sub
编译成ocx控件.运行生成的测试页.text中默认的是text1
如何将服务器端的数据传递给ocx呢?
使用microsoft activex control pad这个工具,可以很容易找到.
直接用这个工具把测试页打开.
菜单->edit->edit activex control,呵呵,打开了一个可视化的界面.
看到了吧,有一个属性框,我们可以进行设置,设置完成以后的代码如下:
<html>
<head>
<title>new page</title>
</head>
<body>
<object id="getclient" width=507 height=440
classid="clsid:890d1028-298b-45cf-9a64-6ed5a5bacbc9"
codebase="http://localhost/xml/focx.ocx">
<param name="_extentx" value="13414">
<param name="_extenty" value="11642">
<param name="getinfo" value="这是ocx得到的客户端读卡器的信息">
</object>
</body>
</html>
增加了id,id就是我们用来访问的标志.还有我们的属性getinfo,我们也设定初始值了
好了,运行.
text中就出现了我们设定的值”这是ocx得到的客户端读卡器的信息”
我们把上边的页面改成asp的,看代码:
<html>
<head>
<title>龙卷风测试页</title>
</head>
<body>
<%
dim svalue
svalue="这是ocx得到的客户端读卡器的信息"
%>
<object id="getclient" width=507 height=440
classid="clsid:56dfca88-f5b8-4879-853b-97fe504423fd"
codebase="http://localhost/xml/focx.ocx">
<param name="_extentx" value="13414">
<param name="_extenty" value="11642">
<param name="getinfo" value="<%=svalue%>">
</object>
</body>
</html>
ok,运行即可
我们看看第二种情况
运行时得到数据
<html>
<head>
<title>龙卷风测试页</title>
<%
dim svalue
svalue="这是ocx得到的客户端读卡器的信息"
%>
<script id=clienteventhandlersjs language=javascript>
<!–
function button1_onclick()
{
getclient.getinfo=<%=svalue%>;
}
//–>
</script>
</head>
<body>
<object id="getclient" width=507 height=440
classid="clsid:56dfca88-f5b8-4879-853b-97fe504423fd"
codebase="http://localhost/xml/focx.ocx">
<param name="_extentx" value="13414">
<param name="_extenty" value="11642">
</object>
<input id=button1 type=button value=button name=button1 language=javascript onclick="return button1_onclick()">
</body>
</html>
运行后,点击按钮即可看到效果.
未完待续
