×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

asp.net问题,帮忙看看

本文发表在 rolia.net 枫下论坛文件1:
<%@ Page Language="VB" %>
<script language="vb" runat="server">
Sub Page_Load(Source As Object, E as EventArgs)
If Not IsPostBack Then
MyButton.Text = "Save Cookie"
MyDropDownList.Items.Add("Blue")
MyDropDownList.Items.Add("Red")
MyDropDownList.Items.Add("Gray")
End If
End Sub
Public Sub Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim MyCookie As New HttpCookie("Background")
MyCookie.Value = MyDropDownList.SelectedItem.Text
Response.Cookies.Add(MyCookie)
End Sub
</script>
<html>
<body>
<form id="CookieForm" method="post" runat="server">
<asp:DropDownList id=MyDropDownList runat="server"/>
<asp:button id=MyButton runat="server" OnClick="Click"/>
</form>
</body>
</html>

文件2.
<%@ Page Language="VB" %>
<script language="vb" runat="server">
Sub Page_Load(Source As Object, E as EventArgs)
Response.Cache.SetExpires(DateTime.Now)
End Sub
</script>
<html>
<body bgcolor="<%=Request.Cookies("Background").Value%>">
</body>
</html>

错误信息:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

为什么?这是书上的例子,是不是设置有问题,cookie已经设为接受全部更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / asp.net问题,帮忙看看
    本文发表在 rolia.net 枫下论坛文件1:
    <%@ Page Language="VB" %>
    <script language="vb" runat="server">
    Sub Page_Load(Source As Object, E as EventArgs)
    If Not IsPostBack Then
    MyButton.Text = "Save Cookie"
    MyDropDownList.Items.Add("Blue")
    MyDropDownList.Items.Add("Red")
    MyDropDownList.Items.Add("Gray")
    End If
    End Sub
    Public Sub Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim MyCookie As New HttpCookie("Background")
    MyCookie.Value = MyDropDownList.SelectedItem.Text
    Response.Cookies.Add(MyCookie)
    End Sub
    </script>
    <html>
    <body>
    <form id="CookieForm" method="post" runat="server">
    <asp:DropDownList id=MyDropDownList runat="server"/>
    <asp:button id=MyButton runat="server" OnClick="Click"/>
    </form>
    </body>
    </html>

    文件2.
    <%@ Page Language="VB" %>
    <script language="vb" runat="server">
    Sub Page_Load(Source As Object, E as EventArgs)
    Response.Cache.SetExpires(DateTime.Now)
    End Sub
    </script>
    <html>
    <body bgcolor="<%=Request.Cookies("Background").Value%>">
    </body>
    </html>

    错误信息:
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    为什么?这是书上的例子,是不是设置有问题,cookie已经设为接受全部更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • 看上去好像在执行new的时候,堆栈没有空间或者其他什么错误,导致new失败。
    • why not just simply debug it ?
    • works for me