title: Disable Postback on button ASP.NET c#
body: <p>here is an example of what I am doing</p>
  
  <pre><code>Page Load
  {
     //Adds items to a panel (not an updatepanel just a normal panel control)
  }
  
   protected void btnNexMod_Click(object sender, EventArgs e)
  {
  
     // Calls DoWork() and Appends more items to the same panel
  }
  </code></pre>
  
  <p>My problem is that the asp:button is doing a postback as well as calling <code>DoWork()</code></p>
  
  <p>Therefore, re-calling my page load, re-initializing my panel :(</p>
  
  <p>I want my items that I have added to the panel to stay there!</p>
  
  <p>All help appreciated, not looking for a hand you the answer kind-of deal.  Any steps are appreciated thanks!</p>
  
  <p>Here is an exact example of my problem.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
  
      CheckBox chkbox = new CheckBox();
      chkbox.Text = "hey";
      chkbox.ID = "chk" + "hey";
  
      // Add our checkbox to the panel
      Panel1.Controls.Add(chkbox);
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
      CheckBox chkbox = new CheckBox();
      chkbox.Text = "hey";
      chkbox.ID = "chk" + "hey";
  
      // Add our checkbox to the panel
      Panel1.Controls.Add(chkbox);
  }
  </code></pre>
  
  <p>Only thing on the page is a empty panel and a button with this click even handler.</p>
  
  <p>I have also tried this and it still doesn't work.  Now its clearing the initial item appended to the panel.</p>
  
  <pre><code>if (!Page.IsPostBack) // to avoid reloading your control on postback
  {
  
      CheckBox chkbox = new CheckBox();
      chkbox.Text = "Initial";
      chkbox.ID = "chk" + "Initial";
  
      // Add our checkbox to the panel
      Panel1.Controls.Add(chkbox);
  }
  </code></pre>