Problem with page lifecycle
Posted
by toraan
on Stack Overflow
See other posts from Stack Overflow
or by toraan
Published on 2010-03-24T12:51:54Z
Indexed on
2010/03/24
12:53 UTC
Read the original article
Hit count: 415
ASP.NET
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.
© Stack Overflow or respective owner