簡體   English   中英

ASP.NET代碼背后的ASP控件

[英]asp control from ascx codebehind

我知道已經被問過數百次了,但是我找不到解決問題的方法。 我有這個ascx文件:

<%@ 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>

這段代碼是:

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

嘗試編譯時,出現錯誤:當前上下文中不存在名稱“ test1”

我應該注意,這兩個文件不在同一目錄中(是否需要?),並且似乎無法生成designer.cs文件(試圖在“設計”模式下編輯ascx文件,但未出現)。 我從另一個項目復制過來的ascx文件。

謝謝你的幫助

如果沒有設計器文件,則需要手動將引用添加到test1。 將此添加到您的代碼隱藏。 Studio創建的部分類將所有內容鏈接在一起,而沒有設計器文件,您會丟失參考。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM