A.D. A.D. - 1 month ago 9
ASP.NET (C#) Question

I cannot access my Div from the Code behind

I do not manage to access a div element from code behind in ASP.NET:

Inside my aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ContactForm.aspx.cs" Inherits="Form_Mailer_ContactForm" %>
...
<div runat="server" id="SentFormDiv">
<s>my content</s>
</div>


Inside the corresponding .cs file (ContactForm.aspx):

protected void Page_Load(object sender, EventArgs e)
{
this.SentFormDiv.Visible=false;
}


I get the usual compilation error message:


does not contain a definition for 'SentFormDiv' and no extension
method 'SentFormDiv' accepting a first argument of type
'xxx.SentFormDiv' could be found (are you missing a using directive or
an assembly reference?)


The odd part is that is I start typing
SentFor
into the code behind, the Intellisense does suggest me
SentFormDiv
!!

What did I miss?

Answer

Please reference this SO question for help. Without seeing your full code, there is no way to give you a definitive answer. Also, as an aside, this.SentFormDiv can be simplified to SentFormDiv.