newSession
은 Session
변수의 이름이 잘못되었습니다. 그러나 이미 완료 한 것처럼 인덱서를 사용해야합니다. 가독성을 높이려면 대신 정적 인 속성을 사용할 수 있습니다. 그런 다음 인스턴스없이 두 번째 페이지의 첫 번째 페이지에서 액세스 할 수 있습니다.
페이지 1 (또는 당신이 좋아하는 곳) : 이제
public static string TestSessionValue
{
get
{
object value = HttpContext.Current.Session["TestSessionValue"];
return value == null ? "" : (string)value;
}
set
{
HttpContext.Current.Session["TestSessionValue"] = value;
}
}
당신은/얻을에서 첫 페이지에 예를 들어, 모든 곳에서 설정할 수있는 TextChanged
-handler :
protected void TextBox1_TextChanged(Object sender, EventArgs e)
{
TestSessionValue = ((TextBox)sender).Text;
}
및 두 번째 페이지에서 읽으십시오 :
protected void Page_Load(Object sender, EventArgs e)
{
this.Label1.Text = Page1.TestSessionValue; // assuming first page is Page1
}
나는 그 질문을 보았지만 나의 것은 해시 테이블을 포함하지 않는다. – Carrie
@Carrie'HashTable'을'TextBox.Text'로 대체하십시오 - 비올라! – Jesse