namespace Test_KMH
{
public partial class Ex_ViewState : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// 뷰스테이트에 기본값 설정
ViewState["Count"] = 0;
SetCount();
}
}
protected void SetCount()
{
lbl_Text.Text = ViewState["Count"].ToString();
}
protected void btn_Add_Click(object sender, EventArgs e)
{
//'+'버튼 클릭시 뷰스테이트의 값 1증가
ViewState["Count"] = Convert.ToInt32(ViewState["Count"]) + 1;
SetCount();
}
protected void btn_Del_Click(object sender, EventArgs e)
{
//'-'버튼 클릭시 뷰스테이트의 값 1감소
ViewState["Count"] = Convert.ToInt32(ViewState["Count"]) - 1;
SetCount();
}
}
}