在尝试保存订单时,我们首先从会话加载对象。这有效。 然后我们将信息添加到订单并将其重新放入会话中。 然后我收到并且对象引用没有设置为对象错误的实例。
Private Sub SaveOrder()
'load the order
Order = Session("Order")
'Add order information here
Session("Order") = Order 'The error is occurring here.
End Sub
堆栈跟踪如下:
Error Path: Contact.aspx
Error Detail: Object reference not set to an instance of an object.
Error Source: Void __RenderContent1(System.Web.UI.HtmlTextWriter, System.Web.UI.Control)
Error Stack Trace: at ASP.orderentry_uc3_contact_aspx.__RenderContent1(HtmlTextWriter __w, Control parameterContainer) in C:\Portal Websites\Portals\OrderEntry\UC3\Contact.aspx:line 9
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
对此有任何帮助将非常感激。
添加了请求的代码:
Imports ComponentArt.Web.UI
Partial Class OrderEntry_UC3_Contact
Inherits Company.Pages.CompanyPage
Public Order As Company.Orders.UC3.Order
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
If Valid() Then
SaveOrder() 'This is line 9
Response.Redirect("Payment.aspx")
End If
End Sub
我已经添加了aspx页面的顶部(整个事情太大了)。
<%@ Page Language="VB" MasterPageFile="~/Portal/PortalNoFooter.master" AutoEventWireup="false"
EnableTheming="true" CodeFile="Contact.aspx.vb" Inherits="OrderEntry_UC3_Contact"
Title="Contact" %>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
//To large to submit the whole thing
</asp:Content>
enter code here
答案 0 :(得分:1)
您的代码示例不显示Page_Load
或aspx文件第9行周围的确切行,但听起来您假设将始终填充Order
。如果您仅在非回发期间在Order
中加载Page_Load
对象,则当用户单击该按钮时,Order
对象在页面生命周期中的加载时间不够早。 / p>
尝试删除对IsPostback
的检查,并始终从会话中重新加载Order
对象。