public partial class Site : System.Web.UI.MasterPage { int i = 0; //эта переменная не выполняется в обработчике дважды // происходит переинициализация LinkButton link = new LinkButton(); public void link_Click(object sender, EventArgs e) { i++; //здесь происходит событие увеличения переменной i link.Text = i; } protected void Page_Load(object sender, EventArgs e) { link.Text = "+++"; link.Click += new EventHandler(link_Click); form.Controls.Add(l); form.Controls.Add(link) } } 

More precisely, it is executed once, as if the whole page is being reinitialized, but old data is added to the link initialization itself.

the point is that static data changes, but remains in memory when even the browser is reset.
if the project code is not changed, then the next application launch gives out the data that was initialized in the previous one

 class ins { public static int i; public void count() { i++; } public static int getI() { return i; } } 
  • one
    Nothing is clear. First is WinForms? Secondly, describe exactly what you see. Third, why don't you set breakpoints in the functions you are interested in and find out if functions are called and how many times? - VladD
  • one
    @VKonstantin, Try to write more detailed questions. Explain what you see the problem, how to reproduce it, etc. - Nicolas Chabanovsky
  • @VladD, judging by inheritance: WebForms - Grundy

0