Writing and reading cookies are boring. By the way, I reviewed what I learned!

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.