두 가지 다른 메소드간에 공유되는 객체의 배열을 갖고 싶습니다.다른 이벤트에서 동일한 객체에 액세스
내 웹 페이지에서 button1을위한 온 클릭은 objectArray을 위해 필요한 값을 채우는 방법 항목을 호출합니다. button2에 대한 onclick 메서드는 method1과 동일한 데이터로 동일한 objectArray에 액세스 할 수 있어야합니다.
using myWebReference;
{
public partial class _Default : System.Web.UI.Page
{
ObjectArray[] myObjects = new ObjectArray[100];
public void Page_Load(object sender, EventArgs e)
{
//I have nothing in here at the moment
}
public void method1(object sender, EventArgs e)
{
//myObjects[]'s values are calculated and assigned here.
}
public void method2(object sender, EventArgs e)
{
String key = myObjects[0].value;
//when I try to get data within myObjects here, myObjects does exist,
//but it is empty and I get a null reference error when I try to use its values.
}
}
나는 일반적으로 asp.net 및 웹에 대한 몇 가지 샘플 및 \ 또는 책을 읽고 함께 가야 좋을 것 ... 다음은 각 요청에 다시 생성됩니다 페이지 클래스를 가지고, 따라서 myObjects는 비어 있습니다. 각 버튼 클릭은 새로운 요청입니다. myObjects를 일부 저장소에 저장하고 (pageLoad 또는 유사한 이벤트에 복원) 클라이언트에 보내야하고 button2를 클릭 할 때 서버로 다시 보내야합니다. – Felix