필자는 기본 ASP.NET 웹 응용 프로그램 템플릿을 주위에 연주하고 다음 코드는 예외가 발생합니다 :의 인스턴스로 설정되지 않았습니다ASP.NET/C는 # 혼란
Object 참조 목적.
생성 된 버튼을 클릭하면.
누구든지 기술적 인 설명을 제공 할 수 있습니까?
참고 1 : 마크 업은 그 안에 자리 표시자가있는 빈 페이지입니다 (아래 참조).
참고 2 : LinkButton
을 Button
으로 바꾸고 코드가 예외를 throw하지 않고 작동합니다.
public partial class test : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
foo();
}
protected override void OnLoad(EventArgs e)
{
foo();
}
protected void foo()
{
placeholder1.Controls.Clear();
placeholder1.Controls.Add(new Button() { Text = "test", ID = "btn" });
}
}
마크 업 :
PLACEHOLDER1 또는 placeholder1.Controls 중 하나가 null처럼 보이는<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApplication1.test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder runat="server" ID="placeholder1" />
</div>
</form>
</body>
</html>
예외는 무엇입니까? – Brandon
개체 참조가 개체의 인스턴스로 설정되지 않았습니다. – maxp
던져진 예외는 무엇입니까? – Oded