⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex39.vb

📁 这是该书上的所有源代码,不错
💻 VB
字号:
Imports System
Imports System.Web
Imports System.Web.HttpCookie

Public Class ex39
    Inherits System.Web.UI.Page
    Protected WithEvents name As System.Web.UI.WebControls.TextBox
    Protected WithEvents password1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents password2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents question As System.Web.UI.WebControls.TextBox
    Protected WithEvents answer As System.Web.UI.WebControls.TextBox
    Protected WithEvents truename As System.Web.UI.WebControls.TextBox
    Protected WithEvents sex As System.Web.UI.WebControls.DropDownList
    Protected WithEvents birthday As System.Web.UI.WebControls.TextBox
    Protected WithEvents marry As System.Web.UI.WebControls.DropDownList
    Protected WithEvents xuexing As System.Web.UI.WebControls.DropDownList
    Protected WithEvents zhengjian As System.Web.UI.WebControls.DropDownList
    Protected WithEvents number As System.Web.UI.WebControls.TextBox
    Protected WithEvents city As System.Web.UI.WebControls.DropDownList
    Protected WithEvents graduate As System.Web.UI.WebControls.DropDownList
    Protected WithEvents career As System.Web.UI.WebControls.DropDownList
    Protected WithEvents position As System.Web.UI.WebControls.DropDownList
    Protected WithEvents incoming As System.Web.UI.WebControls.DropDownList
    Protected WithEvents company As System.Web.UI.WebControls.DropDownList
    Protected WithEvents tel As System.Web.UI.WebControls.TextBox
    Protected WithEvents mobile As System.Web.UI.WebControls.TextBox
    Protected WithEvents callme As System.Web.UI.WebControls.TextBox
    Protected WithEvents fax As System.Web.UI.WebControls.TextBox
    Protected WithEvents zip As System.Web.UI.WebControls.TextBox
    Protected WithEvents horror As System.Web.UI.WebControls.CheckBoxList
    Protected WithEvents address As System.Web.UI.WebControls.TextBox
    Protected WithEvents CompareValidator1 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator4 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator5 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator6 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents save As System.Web.UI.WebControls.CheckBox
    Protected WithEvents load As System.Web.UI.WebControls.CheckBox
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'组件初始化        
#Region " Web Form Designer Generated Code "

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

        InitializeComponent()
    End Sub
#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub

'保存浏览者输入的信息到cookies中
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
	If save.Checked Then

            Dim cookie As HttpCookie
            cookie = New HttpCookie("mychoices")
            cookie.Values.Add("name", name.Text)
            cookie.Values.Add("password1", password1.Text)
            cookie.Values.Add("password2", password2.Text)
            cookie.Values.Add("question", question.Text)
            cookie.Values.Add("answer", answer.Text)
            cookie.Values.Add("truename", truename.Text)
            cookie.Values.Add("sex", sex.SelectedIndex)
            cookie.Values.Add("birthday", birthday.Text)
            cookie.Values.Add("marry", marry.SelectedIndex)
            cookie.Values.Add("xuexing", xuexing.SelectedIndex)
            cookie.Values.Add("zhengjian", zhengjian.SelectedIndex)
            cookie.Values.Add("number", number.Text)
            cookie.Values.Add("city", city.SelectedIndex)
            cookie.Values.Add("graduate", graduate.SelectedIndex)
            cookie.Values.Add("career", career.SelectedIndex)
            cookie.Values.Add("position", position.SelectedIndex)
            cookie.Values.Add("incoming", incoming.SelectedIndex)
            cookie.Values.Add("company", company.SelectedIndex)
            cookie.Values.Add("tel", tel.Text)
            cookie.Values.Add("mobile", mobile.Text)
            cookie.Values.Add("callme", callme.Text)
            cookie.Values.Add("fax", fax.Text)
            cookie.Values.Add("address", address.Text)
            cookie.Values.Add("zip", zip.Text)
'判断用户选择了那些选项,然后存入cookies中
            Dim i As Integer
            For i = 0 To horror.Items.Count - 1
                If horror.Items(i).Selected Then
                    cookie.Values.Add("horror" & i.ToString, i.ToString)
                End If
            Next
            Dim dt As DateTime = DateTime.Now
            cookie.Values.Add("time", dt.ToString)
'Cookies从不重置
            cookie.Expires = DateTime.MaxValue
            Response.AppendCookie(cookie)

        End If
	Response.Redirect("ok.htm")
    End Sub

'如果用户选择该复选框,则从读出保存在cookies中的数据
    Private Sub load_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles load.CheckedChanged
	If load.Checked Then
'判断Cookies是否存在
	    If Request.Cookies("mychoices") Is Nothing Then
		Response.write("<font color=red><h3>没有这个cookies</h3></font>")
	    End If
'如果cookies存在,则从中读取数据
            If Not Request.Cookies("mychoices") Is Nothing Then

                name.Text = Request.Cookies("mychoices").Values("name")
                password1.Text = Request.Cookies("mychoices").Values("passwored1")
                password2.Text = Request.Cookies("mychoices").Values("passwored2")
                question.Text = Request.Cookies("mychoices").Values("question")
                answer.Text = Request.Cookies("mychoices").Values("answer")
                truename.Text = Request.Cookies("mychoices").Values("truename")
                sex.SelectedIndex = Request.Cookies("mychoices").Values("sex")
                birthday.Text = Request.Cookies("mychoices").Values("birthday")
                marry.SelectedIndex = Request.Cookies("mychoices").Values("marry")
                xuexing.SelectedIndex = Request.Cookies("mychoices").Values("xuexing")
                zhengjian.SelectedIndex = Request.Cookies("mychoices").Values("zhengjian")
                number.Text = Request.Cookies("mychoices").Values("number")
                city.SelectedIndex = Request.Cookies("mychoices").Values("city")
                graduate.SelectedIndex = Request.Cookies("mychoices").Values("graduate")
                career.SelectedIndex = Request.Cookies("mychoices").Values("career")
                position.SelectedIndex = Request.Cookies("mychoices").Values("position")
                incoming.SelectedIndex = Request.Cookies("mychoices").Values("incoming")
                company.SelectedIndex = Request.Cookies("mychoices").Values("company")
                tel.Text = Request.Cookies("mychoices").Values("tel")
                mobile.Text = Request.Cookies("mychoices").Values("mobile")
                callme.Text = Request.Cookies("mychoices").Values("callme")
                fax.Text = Request.Cookies("mychoices").Values("fax")
                address.Text = Request.Cookies("mychoices").Values("address")
                zip.Text = Request.Cookies("mychoices").Values("zip")

                Dim i As Integer
                For i = 0 To horror.Items.Count - 1

                    If Not Request.Cookies("mychoices").Values("horror" & i) Is Nothing Then

                        horror.Items(Request.Cookies("mychoices").Values("horror" & i).ToString).Selected = True
                    End If

                Next

            End If
        End If
'如果没有选中复选框,则刷新该页面
        If Not load.Checked Then
            Response.Redirect("ex39VB.aspx")
        End If
    End Sub

'如果单击重置按钮,则刷新页面
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -