写入、读取 cookie 无聊顺便复习了下前面学的东西!

转自: http://www.cnblogs.com/thcjp/archive/2006/03/01/340323.html

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<script language="vb" runat="server">
'写入cookie
sub writcooks_click(sender as object,e as eventargs)
'定义并创建名为cookieexmp的cookie对象
 dim newcookie as httpcookie = new httpcookie("cookieexmp")
 dim thc as string = cstr(txtname.text)
 dim nnv as string = cstr(sex.selecteditem.text)
'添名为 name ,值为 thc 的子键。后两条语句作用与其内似。
 newcookie.values("name") =thc
 newcookie.values("sex")=nnv
 newcookie.values("dj") = "5"
 newcookie.values("dt") = datetime.now.date()
 newcookie.expires = datetime.now.adddays(10) '这句是做什么的,我不知道,有知道的麻烦告诉我下,谢谢!
 response.cookies.add(newcookie) ' 写入cookie对象
 response.Write("<h1>写入完成</h1><p><p>")
end sub
'读取cookie
sub tbn_click(sender as object, e as eventargs)
'由request对象获取cookieexmp
dim getcookie as httpcookie = request.Cookies("cookieexmp")
response.Write("<h2>以下是读出来的东西</h2><hr><br>")
response.Write("名称:" & getcookie.values("name") & "<br>")
response.Write("性别:" & getcookie.values("sex") & "<br>")
response.Write("会员等级:" & getcookie.values("dj") & "<br>")
response.Write("时间:" & getcookie.values("dt") & "<br>")
end sub
'用户名框动作
sub w_name(sender as object,e as eventargs)
lbl.text="用户名" & txtname.text & "正确,请继续输入"
end sub
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form runat="server">
  <p>请输入用户名:
    <asp:TextBox ID="txtname" AutoPostBack="true" TextMode="SingleLine" runat="server" OnTextChanged="w_name" />  &nbsp;&nbsp;
  <asp:Label ID="lbl" runat="server"/></p>
请选择性别:
<asp:RadioButtonList ID="sex" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
  <p>
    <asp:Button ID="writcooks" Text="写入cookie" runat="server" OnClick="writcooks_click"/>     
    <asp:Button ID="tbn" Text="读取cookie" runat="server" OnClick="tbn_click"/>     
</p>
</form>
</body>
</html>

转载于:https://www.cnblogs.com/lyb0002280/archive/2006/03/01/340391.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值