문제

I have this code in InfoEdition.aspx :

<%@ Page Title="" Language="C#" MasterPageFile="~/Espace_Candidat/SousCandidat.master" AutoEventWireup="true" CodeFile="InfoEdition.aspx.cs" Inherits="Espace_Candidat_InfoEdition" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ChildContent2" Runat="Server">
<div class="span9">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
 </div>
</asp:Content>

In the code behind InfoEdition.aspx.cs when i try to access to the textbox :

public partial class Espace_Candidat_InfoEdition : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
// THE TEXTBOX IS NOT FOUND
      TextBox1.
    }
}

the textbox is not found!!!

  • What are the reasons of this error?
  • How can i fix it?
도움이 되었습니까?

해결책

I think you should be using var txt1 = Content1.FindControl("TextBox1") and then if the txt1 is not null use it as you would normally use TextBox1 ?

var txt1 = Content1.FindControl("TextBox1");
txt1.Text = "some value";

다른 팁

Change CodeFile to Codebehind in the declarations.

UPDATED Check the "Build Action" property of the InfoEdition.aspx page set to? It should be set to "Content".

My answer is a bit late, but one of the things you could do is the check if the designer file exists in the folder where your ASPX page is.

If the designer file is missing, code-behind cannot find your fields.

In order to recreate the designer field, you'll need to rebuild it using the VS2019 Project --> Convert to Web Application menu option

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