Its because in asp.net page postback on every click or in simple words when ever you click on page, it runs again and again. so, what actually you are doing is
int i;
here the value of i will be 0
than on button click it will first increment it to 1 and it will remain as 1
you want some container that can contain your value across the page like session or cache
this might help you
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Cache["i"] = 0;
}
}
protected void Button1_OnClick(object sender, EventArgs e)
{
Cache["i"] = (int)Cache["i"]+ 1;
Response.Write(Cache["i"]);
}