<%@ 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" />
<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>
<!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" />
<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>