내 Default.aspx.cs 코드 숨김 내부에 탭으로 구분 된 텍스트 파일에서 읽은 데이터로 DataTable _dt를 채 웠습니다. Default.aspx에서 버튼을 다시 클릭하면 _dt의 모든 내용을 사용자에게 표시하려고합니다.form1 이름이 현재 컨텍스트에 없습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Net;
using System.Text;
using System.Data;
using System.IO;
...
String strLine = String.Empty;
Int32 iLineCount = 0;
System.IO.StreamReader srdr = new System.IO.StreamReader(filePath);
do
{
strLine = srdr.ReadLine();
if (strLine == null)
{ break; }
if (0 == iLineCount++)
{
_dt = this.CreateDataTableForTabbedData(strLine);
}
this.AddDataRowToTable(strLine, _dt);
}
while (true);
form1.Controls.Add(_dt);
하지만 VS는 다음과 같은 오류를 표시합니다. "이름이 현재 컨텍스트에 존재하지 않습니다." form1은 Default.aspx 내에 존재하지 않지만 Site.Master에는 존재합니다.
필자는 코드 숨김 기능을 사용하기 위해 Default.aspx 내에 form1이 있어야 할 필요가 있음을 알고 있지만, 그렇게하려고하면 Site.master에서 ID를 form2로 변경하면 오류 "페이지에는 서버 쪽 양식 태그가 하나만있을 수 있습니다." Site.Master에 양식을 보관해야하지만 Site.Master.cs에 테이블을 생성하는 코드 숨김을 이동할 수 없습니다.
try this.Controls.Add (_dt); – Mate
포럼 사이트와 달리 Google은 '감사합니다'또는 '도움을 주시면 감사하겠습니다'또는 [so]에 서명하지 않습니다. "[안녕하세요, '고마워,'태그 라인 및 인사말을 게시물에서 삭제해야합니까?] (http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be 참조) -removed-from-posts) –
여기서'form1'이 정의되어 있다고 생각하십니까? –