오류가 발생하면 텍스트를 표시하는 레이블을 설정하려고합니다. 이 오류가 발생하면 레이블에서 NullReferenceException이 발생합니다. 그것에서 찾을 수 있다는 것을 나에게 제안Label.Text를 정의하면 NullReferenceException이 발생합니다.
if (userEmail != null)
{
//If the same email exists
pnlError.Visible = Visible;
lblError.Text = "Error: The email you have entered is already assigned to an account.";
} 내가 빌드 할 때
, 나는 오류를 얻을 : 여기
뒤에 코드에서 label.Text 코드 ASPX 코드.는 여기가 마크 업에 있습니다
<asp:Panel ID="pnlError" runat="server" Visible="false" EnableViewState="false">
<label id="lblError"></label>
</asp:Panel>
당신은이 패널에 싸여 볼 수 있듯이.
protected global::System.Web.UI.WebControls.Panel pnlError;
protected global::System.Web.UI.WebControls.Label lblError;
그것은 언급 할 때마다 것을 가치가있다 : 나는 그것이 aspx.designer.cs에 정의되어
그리고 여기 Label.Text와 같은 기능에 잘 패널의 가시성을 변경할 수 있습니다 마크 업에서 단추 나 패널과 같은 다른 WebControl 요소를 변경하면 aspx.design.cs가 다시 생성되지만 lblError 레이블은 포함되지 않습니다. 삭제를 시도한 다음 디자인을 수동으로 다시 생성 해 보았습니다. 레이블이 패널의 내부에 있기 때문에
'runat = "server"'가 없습니다. –
레이블 태그에 runat = "server"를 추가하면 약 6 개의 오류가 발생합니다. – Frayt
나는 간단한 웹 애플리케이션을 만들었고, 당신이 가진 콘텐츠와'runat = "서버"를 추가했다. aspx.designer.cs 파일의'HtmlGenericControl'이기 때문에 코드를'lblError.InnerText'로 변경해야했습니다. 아마도 '