Why does my ASP.NET UserControl type keep becoming inaccessible?

rammstein242

New Member
I've got an ASP.NET web site that includes a usercontrol that's added programmatically to an ASP.NET web form, using this code:\[code\]var control = (Deal)LoadControl("Deal.ascx");control.ImageFile = dealNode.SelectSingleNode("thumbnail").InnerText;control.ProductName = dealNode.SelectSingleNode("product").InnerText;control.PriceText = dealNode.SelectSingleNode("price").InnerText;DealList.Controls.Add(control);\[/code\]The Deal control is really simple:\[code\]<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Deal.ascx.cs" Inherits="Deal" %><div class="deal"> <img id="DealImage" runat="server" class="dealimage" /> <div class="dealtext"><asp:Label ID="DealLabel" runat="server"></asp:Label></div> <div class="dealprice"><asp:Label ID="DealPriceLabel" runat="server"></asp:Label></div></div>\[/code\]with the code behind it:\[code\]public string ImageFile { get; set; }public string ProductName { get; set; }public string PriceText { get; set; }protected void Page_Load(object sender, EventArgs e){ this.DealImage.Src = "http://stackoverflow.com/questions/12599144/images/" + ImageFile; this.DealLabel.Text = ProductName; this.DealPriceLabel.Text = PriceText;}\[/code\]When I run up the web site in Visual Studio 2010, it usually works fine. However, every so often (usually after a check-in or restarting VS2010), it gives up and won't compile. I get the error:\[code\]The type or namespace name 'Deal' could not be found (are you missing a using directive or an assembly reference?)\[/code\]The problem being the cast in the line:\[code\]var control = (Deal)LoadControl("Deal.ascx");\[/code\]If I comment out the usercontrol's Page_Load code, recompile, then uncomment the code and recompile, everything's OK again.Can anyone tell me what's going on?
 
Back
Top