title: method firing twice during pageload in asp.net
body: <p>I know such questions are asked already on SO, and i also went through most of them but no one satisfied me, so i am posting mine one. Attached is my code. actually i am building a jquery gallery from code from databale. see the code:</p>
  
  <pre><code>  protected void Page_Load(object sender, EventArgs e)
          {
              if (!IsPostBack)
              {
                  DisplayHotProducts();
              }
          }
  
  
  
          private void DisplayHotProducts()
          {
              var dt = ProductData.GetAllHotProducsts();
              if (dt != null &amp;&amp; dt.Rows.Count &gt; 0)
              {
                  StringBuilder sb = new StringBuilder();
                  sb.AppendLine(" &lt;div id='spotlight_products' class='widget_box center_box'&gt;");
                  sb.AppendLine("&lt;div class='wintitle'&gt;");
                  sb.AppendLine(" &lt;div class='inner_wintitle'&gt;");
                  sb.AppendLine("  Hot Products&lt;/div&gt;&lt;/div&gt;");
                  sb.AppendLine("&lt;div class='winbody'&gt;");
                  sb.AppendLine("&lt;div class='mall_focus' id='mall_focus'&gt;");
                  sb.AppendLine("&lt;a id='bp_carousel_prev'&gt;prev&lt;/a&gt;");
                  sb.AppendLine("&lt;a id='bp_carousel_next'&gt;next&lt;/a&gt;");
                  sb.AppendLine("&lt;div id='bp_carousel'&gt;");
                  sb.AppendLine(" &lt;div class='carousel_list'&gt;");
  
  
                  for (int i = 0; i &lt; dt.Rows.Count; i=i+5)
                  {
  
                      sb.AppendLine(" &lt;div class='product_list'&gt;");
                      sb.AppendLine("&lt;div class='bestproduct_wrapper'&gt; &lt;div class='bestproduct'&gt;");
                      sb.AppendLine("   &lt;div class='icon_best'&gt;&lt;/div&gt;");
                      sb.AppendLine("&lt;ul&gt;");
                      sb.AppendLine(" &lt;li class='best_Img'&gt;&lt;span&gt;&lt;/span&gt;&lt;a href='#' target='_blank'&gt; ");
                      sb.AppendLine(string.Format(" &lt;img src='{0}'  width='200' height='200'  /&gt;&lt;/a&gt;&lt;/li&gt;", dt.Rows[i]["ImagePath"]));
                      sb.AppendLine("&lt;/ul&gt;");
                      sb.AppendLine(" &lt;p class='product_name'&gt;");
                      sb.AppendLine(string.Format("&lt;a href='Products/{0}'   target='_blank'&gt;{1}&lt;/a&gt;&lt;/p&gt;", dt.Rows[i]["Id"], dt.Rows[i]["Name"]));
                      sb.AppendLine("&lt;/div&gt;&lt;/div&gt;");
  
                      for (int j = i+1; j &lt;= 4; j++)
                      {
                          sb.AppendLine("&lt;div class='product_item'&gt;");
                          sb.AppendLine("&lt;ul&gt;&lt;li class='product_Img'&gt;");
                          sb.AppendLine(string.Format("&lt;a href='Products/{0}'&gt;&lt;img src='{1}'  width='70' height='70'/&gt;&lt;/a&gt;", dt.Rows[j]["Id"], dt.Rows[j]["ImagePath"]));
                          sb.AppendLine("&lt;/li&gt;&lt;/ul&gt;");
                          sb.AppendLine(string.Format("&lt;p class='product_name'&gt;&lt;a href='Products/{0}'&gt;{1}&lt;/a&gt;&lt;/p&gt;", dt.Rows[j]["Id"], dt.Rows[j]["Name"]));
                          sb.AppendLine("&lt;/div&gt;");
                      }
                  }
  
                  sb.AppendLine(@" &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;");
                  ltlHotProducts.Text = sb.ToString();
              }
          }
      }
  </code></pre>
  
  <p><em><strong>My code behind has the above code only and the page load is firing twice.</em></strong></p>
  
  <p>Also this is code behind of a usercontrol, placed on a page where i have 3 more similar control performing similar functionalities that is , building jquery slideshows from code behind. But the above two user controls has some issues with the img tags as some of them are missing images. Also the page on which the user controls are placed has a master page. Now please suggest me the solution.</p>
  
  <p>So the heirarchy is something like this:</p>
  
  <p><code>Master Page (master) -&gt; Content Page (aspx) -&gt; Has-&gt;3 UserControls (ascx)</code></p>