Considering a simple example of a webpart that adds items to a list based on a simple button click:
public partial class MyVisualWebPartUserControl : UserControl
{
private int cont = 0;
protected void MyButton_Click(object sender, EventArgs e)
{
using (SPSite site = new SPSite("http://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyList"];
SPListItem item = list.Items.Add();
item["Title"] = "Title " + cont++;
//......
}
}
}
}
The title of the element, on each click of a button, should be:
Title 0
Title 1
Title 2
Title 3
Title 4
etc
Off course this isn't the case and this is outputted:
Title 0
Title 0
Title 0
Title 0
Title 0
etc
What options do I have to be able to manage such state inside the webpart?
Can I make it "per user" (each user with his own counter)?