Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'If Not Page.IsPostBack Then
Dim vote_name
Dim vote_item vote_item = Request("vote_item")
vote_name = Request("vote_name")
DataGrid1.Caption = vote_name '==================================================================test
'Label4.Text = Response.Cookies.Item("mysite_cookie").Value 'Dim i As Integer
'For i = 0 To Request.Cookies.Count - 1
' Response.Write("name:" & Request.Cookies.Item(i).Name & "<br>")
' Response.Write("value:" & Request.Cookies.Item(i).Value & "<br>") 'Next
'If Response.Cookies.Item("mysite_cookie").Value <> "vote_ok" Then
' Response.Write("vote_ok is <>")
'End If
'============================================================== '设置投票数据更新
If Response.Cookies.Item("mysite_cookie").Value <> "vote_ok" Then
Response.Cookies.Item("mysite_cookie").Expires = Now.AddDays(3)
Response.Cookies.Item("mysite_cookie").Value = "vote_ok" Dim updatesqlstring As String
updatesqlstring = "update voteitem set item_count = item_count + 1 where item_id = " & vote_item
Dim updatecommand As OleDbCommand = New OleDbCommand(updatesqlstring, OleDbConnection1)
OleDbConnection1.Open()
updatecommand.ExecuteNonQuery()
OleDbConnection1.Close()
Label3.Text = "投票成功!"
Else
Label3.Text = "您已经投过票了!请查看投票结果。"
End If '取得投票列表
Dim sqlstring As String
Dim mycommand As OleDbCommand
sqlstring = "select item_name,item_count,vt_id from voteitem where "
sqlstring += "vt_id = (select vt_id from voteitem where item_id = " & vote_item & ")"
mycommand = New OleDbCommand(sqlstring, OleDbConnection1)
Dim mydataadapter As New OleDbDataAdapter(mycommand)
mydataadapter.Fill(DataSet11, "voteitem") Page.DataBind()
'End If End Sub
问题:If Response.Cookies.Item("mysite_cookie").Value <> "vote_ok" Then 为什么取值总是不等于"vote_ok",另外,还请教能不能动态的设定COOKIE 的NAME值,防止重复投票上是怎么处理的?
'If Not Page.IsPostBack Then
Dim vote_name
Dim vote_item vote_item = Request("vote_item")
vote_name = Request("vote_name")
DataGrid1.Caption = vote_name '==================================================================test
'Label4.Text = Response.Cookies.Item("mysite_cookie").Value 'Dim i As Integer
'For i = 0 To Request.Cookies.Count - 1
' Response.Write("name:" & Request.Cookies.Item(i).Name & "<br>")
' Response.Write("value:" & Request.Cookies.Item(i).Value & "<br>") 'Next
'If Response.Cookies.Item("mysite_cookie").Value <> "vote_ok" Then
' Response.Write("vote_ok is <>")
'End If
'============================================================== '设置投票数据更新
If Response.Cookies.Item("mysite_cookie").Value <> "vote_ok" Then
Response.Cookies.Item("mysite_cookie").Expires = Now.AddDays(3)
Response.Cookies.Item("mysite_cookie").Value = "vote_ok" Dim updatesqlstring As String
updatesqlstring = "update voteitem set item_count = item_count + 1 where item_id = " & vote_item
Dim updatecommand As OleDbCommand = New OleDbCommand(updatesqlstring, OleDbConnection1)
OleDbConnection1.Open()
updatecommand.ExecuteNonQuery()
OleDbConnection1.Close()
Label3.Text = "投票成功!"
Else
Label3.Text = "您已经投过票了!请查看投票结果。"
End If '取得投票列表
Dim sqlstring As String
Dim mycommand As OleDbCommand
sqlstring = "select item_name,item_count,vt_id from voteitem where "
sqlstring += "vt_id = (select vt_id from voteitem where item_id = " & vote_item & ")"
mycommand = New OleDbCommand(sqlstring, OleDbConnection1)
Dim mydataadapter As New OleDbDataAdapter(mycommand)
mydataadapter.Fill(DataSet11, "voteitem") Page.DataBind()
'End If End Sub
问题:If Response.Cookies.Item("mysite_cookie").Value <> "vote_ok" Then 为什么取值总是不等于"vote_ok",另外,还请教能不能动态的设定COOKIE 的NAME值,防止重复投票上是怎么处理的?
解决方案 »
- 请问如果在asp.net页面中操作googlemap
- 已添加项。字典中的关键字:“Ajax.JSON.HtmlControls.HtmlInputCheckBoxConverter 错误
- XXX.aspx.designer.cs 不见了.在线等
- C#代码备份与还原数据库
- css分页,怎么在asp.net中用????
- 关于搜索引擎
- 一个简单的问题,请帮忙看一下!!
- 求《ASP.NET办公自动化系统开发实例导航》一书的光盘代码
- 请问一个使用asp.net c#中操作word的问题.
- 大网站需要拆分小模块吗?
- 将iframe的变量传到父页的控件中.
- 请问在iframe编辑模式里,在一个表格里添加一个表格,里面的表格下面为什么还有一个空行,如何消除?顶着有分!
取值用dim str as string=Request.Cookies.Item("mysite_cookie").Value
HttpCookie myCookie = new HttpCookie("MyTestCookie");
DateTime now = DateTime.Now;// Set the cookie value.
myCookie.Value = now.ToString();
// Set the cookie expiration date.
myCookie.Expires = now.AddMinutes(1);// Add the cookie.
Response.Cookies.Add(myCookie);Response.Write("<p> The cookie has been written.");
//读取
HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie = Request.Cookies["MyTestCookie"];// Read the cookie information and display it.
if (myCookie != null)
Response.Write("<p>"+ myCookie.Name + "<p>"+ myCookie.Value);
else
Response.Write("not found");
//MSDN