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





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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.
.NET Development2  

 
 
ROSE3000





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

NOT FOUND ANY ANSWER

PLS HELP ON ABOVE PROBLEM



 
 
MihaiBejenariu





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

Would you please the code you have in
WMProShop.Students.CreditCardInfo.PaymentControl property 




 
 
ROSE3000





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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

}



 
 
ROSE3000





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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

}



 
 
MihaiBejenariu





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

Also, please post the code in

WMProShop.Controls.Payment.SubtotalAndPaymentInfo.Page_Load.

Thanks.



 
 
ROSE3000





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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

HERE







<!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>



 
 
ROSE3000





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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();

}

}



 
 
ROSE3000





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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);

}

}

}



 
 
MihaiBejenariu





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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.



 
 
tanwy83





PostPosted: .NET Framework Data Access and Storage, System.InvalidCastException: Unable to cast object of type 'ASP.students_payment_aspx' to type 'WMProShop.Payment'. Top

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