문제

I know this has been asked hundred of times, however I cannot find the solution to my problem. I have this ascx file:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="FrontClass.CreateClientPortals.TopNavBar, FrontClass.CreateClientPortals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=40f3875c9d373801"%>
<div>
  <asp:Literal ID="test1" runat="server" visible="true">some text</asp:Literal>
</div>

And this codebehind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace FrontClass.CreateClientPortals
{
    public partial class TopNavBar : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            test1.visible = false;
        }
    }
}

When trying to compile, I receive the error: The name 'test1' does not exist in the current context

I should note that both files are not in the same directory (do they need to be?) and I cannot seem to generate designer.cs file (tried editing ascx file in Design mode, but it did not appear). ascx file I copied over from another project.

thanks for helping out

도움이 되었습니까?

해결책

Without the designer file you'll need to add the references to test1 manually. Add this to your code-behind. Studio creates the partial classes that links everything together and without the designer file you're missing the reference.

protected global::System.Web.UI.WebControls.Literal test1;

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top