Writing and reading cookies are boring. By the way, I reviewed what I learned!
Last Update:2018-12-08
Source: Internet
Author: User
<% @ 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">
'Write cookie
Sub writcooks_click (sender as object, e as eventargs)
'Define and create a cookie object named cookieexmp
Dim newcookie as httpcookie = new httpcookie ("cookieexmp ")
Dim thc as string = cstr (txtname. text)
Dim nnv as string = cstr (sex. selecteditem. text)
'Add a subkey named name with the value of thc. The last two statements serve the same purpose as the previous one.
Newcookie. values ("name") = thc
Newcookie. values ("sex") = nnv
Newcookie. values ("dj") = "5"
Newcookie. values ("dt") = datetime. now. date ()
Newcookie. expires = datetime. now. adddays (10) '. I don't know what to do. Please tell me if you have any knowledge. Thank you!
Response. cookies. add (newcookie) 'write cookie object
Response. Write ("End sub
'Read cookie
Sub tbn_click (sender as object, e as eventargs)
'Obtain cookieexmp from the request object
Dim getcookie as httpcookie = request. Cookies ("cookieexmp ")
Response. Write ("Response. Write ("name:" & getcookie. values ("name") & "<br> ")
Response. Write ("Gender:" & getcookie. values ("sex") & "<br> ")
Response. Write ("membership level:" & getcookie. values ("dj") & "<br> ")
Response. Write ("time:" & getcookie. values ("dt") & "<br> ")
End sub
'User Name box action
Sub w_name (sender as object, e as eventargs)
Lbl. text = "username" & txtname. text & "Correct. Please enter"
End sub
</Script>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Body>
<Form runat = "server">
<P> enter the User Name:
<Asp: TextBox ID = "txtname" AutoPostBack = "true" TextMode = "SingleLine" runat = "server" OnTextChanged = "w_name"/> & nbsp;
<Asp: Label ID = "lbl" runat = "server"/> </p>
Select gender:
<Asp: RadioButtonList ID = "sex" runat = "server" RepeatDirection = "Horizontal">
<Asp: ListItem> male </asp: ListItem>
<Asp: ListItem> female </asp: ListItem>
</Asp: RadioButtonList>
<P>
<Asp: Button ID = "writcooks" Text = "Write cookie" runat = "server" OnClick = "writcooks_click"/>
<Asp: Button ID = "tbn" Text = "read cookie" runat = "server" OnClick = "tbn_click"/>
</P>
</Form>
</Body>
</Html>