RSS Forums RSS
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 12357 | Replies: 0 | Thread Tools  Display Modes
Reply
Join Date: Sep 2005
Posts: 1
Reputation: toddpinksen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toddpinksen toddpinksen is offline Offline
Newbie Poster

System.InvalidCastException: Specified cast is not valid

  #1  
Sep 7th, 2005
Hi,

I've been modifying the ASPNetStore Application to create my own. Everything's been working fine, but I recently had to reinstall VS.NET. Now I am getting the following error on both the ASPNetStore app. as well as on my custom app. Here is the code for my custom app:

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

namespace Pearls.SaltWaterPearls
{
/// <summary>
/// Summary description for Product.
/// </summary>
public class Product : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder plhProductTemplate;
protected System.Web.UI.WebControls.Label lblProductName;


void Page_Load(Object sender , EventArgs e)
{
int intProductID;
string strProductTemplate;
ProductTemplate objProductTemplate;
intProductID = System.Convert.ToInt32(Context.Items[ "ProductID" ]);
strProductTemplate = CachedData.GetProductTemplate( intProductID );
strProductTemplate = string.Format( "ProductTemplates/{0}.ascx", strProductTemplate );
objProductTemplate = (StoreComponents.ProductTemplate)LoadControl( strProductTemplate );
plhProductTemplate.Controls.Add( objProductTemplate ) ;
lblProductName.Text = objProductTemplate.ProductName.ToString();

}
}

The error occurs at the line:

objProductTemplate = (StoreComponents.ProductTemplate)LoadControl( strProductTemplate );

It's very puzzling since it worked for several months prior to reinstalling the software. I'd appreciate any insight which can help me solve this problem.

Thanks in advance

Todd
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:10 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC