Problem with page lifecycle
- by toraan
I have a basic question:
my page:
<div>
<asp:LinkButton ID="LinkButton0" onclick="LinkButton_Click" runat="server" CommandArgument="0">0</asp:LinkButton>
<asp:LinkButton ID="LinkButton1" onclick="LinkButton_Click" runat="server" CommandArgument="1">1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" onclick="LinkButton_Click" runat="server" CommandArgument="2">2</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" onclick="LinkButton_Click" runat="server" CommandArgument="3">3</asp:LinkButton>
</div>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
Foo (PageIndex);
}
int _pageIndex;
public int PageIndex
{
get
{
object objPage = ViewState["_pageIndex"];
if (objPage == null)
{
_pageIndex = 0;
}
else
{
_pageIndex = (int)objPage;
}
return _pageIndex;
}
set {ViewState["_pageIndex"] = value; }
}
protected void LinkButton_Click(object sender, EventArgs e)
{
PageIndex = int.Parse(((LinkButton)sender).CommandArgument);
}
The problem is with Page_Load event, I expect to get new PageIndex after the linkbutton is clicked.