title: stop refreshing page on button click
body: <p>I need to make the asp button to not refresh the whole page when I click it.</p>
  
  <p>my code is just to make a picture change to another picture but the index of the picture is set in the page load method. And every time you click the button to go to the next picture index, the whole page refreshes and calls the page load method. That then sets the index back to 0.</p>
  
  <p>how can I make the page stop calling the page load method when I click a button</p>
  
  <p>Here's the basic code I'm using</p>
  
  <p>in a table:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt; &lt;asp:Button ID="Button1" runat="server" Text="Prev" OnClick="Button1_Click" OnClientClick="return false"/&gt; &lt;/td&gt;
      &lt;td&gt; &lt;img ID="pic" alt="" src="010.JPG" runat="server" width="200" height="200" /&gt; &lt;/td&gt;
      &lt;td&gt; &lt;asp:Button ID="Button2" runat="server" Text="Next" OnClick="Button2_Click" OnClientClick="return false"/&gt; &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>and this is the .cs file</p>
  
  <pre><code>private List&lt;String&gt; imagePathList = new List&lt;String&gt; { };
  private List&lt;Boolean&gt; isActivePath = new List&lt;Boolean&gt; { };
  
  protected void Page_Load(object sender, EventArgs e)
  {
          Debug.WriteLine("GALLARY *page load*");
  
          pic.Width = 200;
          pic.Height = 200;
  
          addToList();
  
          getImagePath(1);
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
      Debug.WriteLine("GALLARY *Button1_Click*");
      int index = getActive();
      getImagePath(index = index - 1); 
  }
  protected void Button2_Click(object sender, EventArgs e)
  {
      Debug.WriteLine("GALLARY *Button2_Click*");
      int index = getActive();
      getImagePath(index = index + 1);
  }
  
  private void getImagePath(int index)
  {
      Debug.WriteLine("GALLARY *getImagePath* index = "+index);
      int length = imagePathList.Count;
  
      if (index &lt; length &amp;&amp; index &gt;= 0)
      {
          //pic.Src = imagePathList[index];
          //pic.Alt = imagePathList[index];
          pic.Src = imagePathList[index];
          pic.Alt = imagePathList[index];
          setActive(index);
      }
      else
      {
          pic.Src = "DOES NOT EXIST";
          pic.Alt = "DOES NOT EXIST";
      }
  }
  
  private void addToList()
  {
      Debug.WriteLine("GALLARY *addToList*");
      imagePathList.Clear();
      isActivePath.Clear();
  
      addImage("08.JPG");
      addImage("09.JPG");
      addImage("010.JPG");
      addImage("011.JPG");
      addImage("012.JPG");
  }
  
  private void addImage(String filename)
  {
      Debug.WriteLine("GALLARY *addImage* filename = "+filename);
      imagePathList.Add(filename);
      isActivePath.Add(false);
  }
  private void setActive(int index)
  {
      Debug.WriteLine("GALLARY *setActive* index = " + index);
      for (int i = 0; i &gt; isActivePath.Count; i++)
      {
          isActivePath[i] = false;
      }
  
      isActivePath[index] = true;
  }
  private int getActive()
  {
      Debug.Write("GALLARY *getActive*");
      int temp = 0;
      for (int i = 0; i &gt; isActivePath.Count; i++)
      {
          if (isActivePath[i] == true)
          {
              temp = i;
          }
      }
      Debug.WriteLine("index = " + temp);
      return temp;
  }
  </code></pre>