Share via


System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'.

Question

Monday, October 30, 2006 5:43 AM

 

I GET THE FOLLOWING PROBLEM  WHEN I AM MAKING THE  CHANGE  IN THE APPLICATION  AND REUPLOAD ON THE SERVER PLS PROVIDE ME THE SOLUTION SOON  

THANKS

 

Server Error in '/' Application.


Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'.

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.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'.]
   WMProShop.Students.CreditCardInfo.get_PaymentControl() +69
   WMProShop.Controls.Payment.SubtotalAndPaymentInfo.Page_Load(Object sender, EventArgs e) +139
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

All replies (10)

Monday, October 30, 2006 5:53 AM

NOT FOUND ANY ANSWER

PLS HELP ON ABOVE PROBLEM

 


Monday, October 30, 2006 7:15 AM

Would you please the code you have in

WMProShop.Students.CreditCardInfo.PaymentControl property?

Monday, October 30, 2006 7:24 AM

here is the code of the page

 

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using WMProShop.Controls.Payment;

 

/// <summary>

/// Summary description for SchoolCatalog1.

/// </summary>

public partial class Payment : System.Web.UI.Page

{

protected void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

public PaymentInfo PaymentControl

{

get

{

return m_PaymentInfo;

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

}

#endregion

}


Monday, October 30, 2006 7:25 AM

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using WMProShop.Controls.Payment;

 

/// <summary>

/// Summary description for SchoolCatalog1.

/// </summary>

public partial class Payment : System.Web.UI.Page

{

protected void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

public PaymentInfo PaymentControl

{

get

{

return m_PaymentInfo;

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

}

#endregion

}


Monday, October 30, 2006 7:32 AM

Also, please post the code in

WMProShop.Controls.Payment.SubtotalAndPaymentInfo.Page_Load.

Thanks.

 


Monday, October 30, 2006 7:46 AM

HERE IS COMPLETE CODE FOR THE CODE BEHIND PAGE IF U WANT THEN I WILL INCLUDE THE HTML CODE ALSO

 HERE

 

<%@ Reference Control="~/controls/payment/paymentinfo.ascx" %>
<%@ Register TagPrefix="uc2" TagName="PaymentInfo" Src="../Controls/Payment/PaymentInfo.ascx" %>
<%@ Page language="c#" Inherits="WMProShop.Payment" CodeFile="Payment.aspx.cs" %>
<%@ Register TagPrefix="uc1" TagName="EmptyMenu" Src="../Controls/Menus/EmptyMenu.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Footer" Src="../Controls/Layout/Footer.ascx" %>
<%@ Register TagPrefix="uc2" TagName="Header" Src="../Controls/Layout/Header.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>Online Proshop</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body leftMargin="0" topMargin="0" rightmargin="0">
  <form id="Form1" method="post" runat="server">
   <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="775" border="0">
    <TR>
     <TD>
      <uc2:Header id="Header1" runat="server"></uc2:Header></TD>
    </TR>
    <TR>
     <TD>
      <uc1:EmptyMenu id="EmptyMenu1" runat="server"></uc1:EmptyMenu></TD>
    </TR>
    <TR>
     <TD vAlign="top"><BR>
      <uc2:PaymentInfo id="m_PaymentInfo" runat="server"></uc2:PaymentInfo></TD>
    </TR>
    <TR>
     <TD vAlign="top"><BR>
      <uc1:Footer id="Footer1" runat="server"></uc1:Footer></TD>
    </TR>
   </TABLE>
  </form>
 </body>
</HTML>


Monday, October 30, 2006 7:48 AM

HERE IS THE CODE

 

 

//===========================================================================

// This file was generated as part of an ASP.NET 2.0 Web project conversion.

// This code file 'App_Code\Migrated\controls\payment\Stub_subtotalandpaymentinfo_ascx_cs.cs' was created and contains an abstract class

// used as a base class for the class 'Migrated_SubtotalAndPaymentInfo' in file 'controls\payment\subtotalandpaymentinfo.ascx.cs'.

// This allows the the base class to be referenced by all code files in your project.

// For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995

//===========================================================================

 

 

 

namespace WMProShop.Controls.Payment

{

using System;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using WMProShop.Students;

using CCTranMan;

using WMProShop.BLL;

using System.Diagnostics;

abstract public class SubtotalAndPaymentInfo : System.Web.UI.UserControl

{

abstract public void LoadData();

 

}

 

 

}


Monday, October 30, 2006 7:52 AM

HERE IS THE CODE FOR THE SUBTOTALANDPAYMENTINFO.ASCX.CS

 

 

//===========================================================================

// This file was modified as part of an ASP.NET 2.0 Web project conversion.

// The class name was changed and the class modified to inherit from the abstract base class

// in file 'App_Code\Migrated\controls\payment\Stub_subtotalandpaymentinfo_ascx_cs.cs'.

// During runtime, this allows other classes in your web application to bind and access

// the code-behind page using the abstract base class.

// The associated content page 'controls\payment\subtotalandpaymentinfo.ascx' was also modified to refer to the new class name.

// For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995

//===========================================================================

namespace WMProShop.Controls.Payment

{

using System;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using WMProShop.Students;

using CCTranMan;

using WMProShop.BLL;

using System.Diagnostics;

/// <summary>

/// Summary description for SubtotalAndPaymentInfo.

/// </summary>

public partial class Migrated_SubtotalAndPaymentInfo : SubtotalAndPaymentInfo

{

protected void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

lblError2.Visible = false;

lblWrongInfo.Visible = false;

if(!IsPostBack)

{

PaymentInfo payment = ((CreditCardInfo)Page).PaymentControl;

// PersonInformation billingInfo = ((CreditCardInfo)Page).BillingInfo;

// PersonInformation shippingInfo = ((CreditCardInfo)Page).ShippingInfo;

string strBaseLink = "MM_openBrWindow('{0}','{1}','width={2},height=500,scrollbars=yes,resizeable=yes')";

string filename = PageLinkURLs.TERMS_AND_CONDITIONS.Substring(1);

string strTAndC = "http://" + Request.Url.Host + Request.ApplicationPath + filename;

lnkTermsAndConditions.Attributes.Add("onclick",string.Format(strBaseLink,strTAndC,"TANDC",600));

 

LoadData();

}

}

// public void LoadData()

override public void LoadData()

{

BindPriceTotalControl();

}

private void BindPriceTotalControl()

{

ControlInfoHelper.StateAbbreviations state = OrderHelper.ShippingState;

m_PriceTotalControl.SubTotal = OrderHelper.Subtotal;

m_PriceTotalControl.SalesTax = OrderHelper.TCItemSalesTax;

m_PriceTotalControl.Discount = OrderHelper.DiscountForTCProducts;

m_PriceTotalControl.SubtotalAfterDiscount = OrderHelper.SubtotalAfterDiscount;

m_PriceTotalControl.ShippingAndHandling = OrderHelper.TCItemShippingAndHandling;

m_PriceTotalControl.Total = OrderHelper.TotalCost;

}

 

 

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.imgSubmitBtn.Click += new System.Web.UI.ImageClickEventHandler(this.imgSubmitBtn_Click);

this.imgButtonContinue.Click += new System.Web.UI.ImageClickEventHandler(this.imgButtonContinue_Click);

}

#endregion

private void PayAndContinue()

{

if(Page.IsValid)

{

try

{

//

OrderHelper.SubmitPayment(BuildTransaction());

//

Server.Transfer(PageLinkURLs.ORDER_CONFIRMATION);

}

catch(InvalidTransactionException)

{

lblWrongInfo.Visible = true;

}

catch(InvalidPromotionException)

{

lblPromoExpired.Visible = true;

}

catch(Exception e2)

{

imgSubmitBtn.Visible = false;

imgButtonContinue.Visible = true;

lblError2.Visible = true;

OrderHelper.CompleteOrder();

Trace.Warn("bad tx",e2.ToString(),e2);

Debug.WriteLine(e2.ToString());

}

//Server.Transfer(PageLinkURLs.ORDER_CONFIRMATION);

}

}

private void btnPay_Click(object sender, System.EventArgs e)

{

lblPromoExpired.Visible = false;

lblError2.Visible = false;

PayAndContinue();

}

private CCTranMan.CreditCardTransaction BuildTransaction()

{

CCTranMan.CreditCardTransaction tran = new CreditCardTransaction();

PersonInfoStruct m_BillingInfo = OrderHelper.BillingInfo;

PersonInfoStruct m_ShippingInfo = OrderHelper.ShippingInfo;

// Configure the transaction that will be submitted to the gateway

tran.CustomerFirstName = m_BillingInfo.FirstName;

tran.CustomerLastName = m_BillingInfo.LastName;

tran.CustomerAddress = m_BillingInfo.Address;

tran.CustomerCity = m_BillingInfo.City;

tran.CustomerState = m_BillingInfo.State;

tran.CustomerZipCode = m_BillingInfo.Zip;

tran.CustomerCountry = "US";

tran.CustomerPhone = m_BillingInfo.PhoneNumber;

tran.CustomerEmail = m_BillingInfo.EmailAddress;

// Configure the transaction to contain the shipping info

tran.ShipToFirstName = m_ShippingInfo.FirstName;

tran.ShipToLastName = m_ShippingInfo.LastName;

tran.ShipToAddress = m_ShippingInfo.Address;

tran.ShipToCity = m_ShippingInfo.City;

tran.ShipToState = m_ShippingInfo.State;

tran.ShipToZipCode = m_ShippingInfo.Zip;

tran.ShipToCountry = "US";

// Set up as a test transaction for now

if(ProShopAdminInfoHelper.TestMode == true)

{

tran.TransactionTestRequest = CCTranMan.TristateValue.TristateTrue;

}

else

{

tran.TransactionTestRequest = CCTranMan.TristateValue.TristateFalse;

}

// Set up as authorization

tran.TransactionMode = CCTranMan.TransactionType.AuthorizeCapture;

tran.TransactionAmount = OrderHelper.TotalCost;

tran.CreditCardNumber = m_CreditCardInformation.CreditCardNumber;

tran.CreditCardExpirationDate = m_CreditCardInformation.Expiration;

tran.CreditCardCode = m_CreditCardInformation.SecurityCode;

return tran;

}

private void imgSubmitBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)

{

PayAndContinue();

}

private void imgButtonContinue_Click(object sender, System.Web.UI.ImageClickEventArgs e)

{

string shoppingURL = PageLinkURLs.SHOPPING_CATALOG.Substring(1);

Response.Redirect("http://" + Request.Url.Host + Request.ApplicationPath + shoppingURL);

}

}

}


Monday, October 30, 2006 5:18 PM

It’s obvious the error is on this line of code:

PaymentInfo payment = ((CreditCardInfo)Page).PaymentControl;

In your code, the PaymentControl belongs to Payment class.

  1. Replace CreditCardInfo with Payment.

Or

2. Check if a CreditCardInfo class has a property PaymentControl having PaymentInfo type.

 

 


Wednesday, May 16, 2007 8:21 AM

there is not a same object so u cant force it to cast