title: How to stop ListView from populating ASPX on pageload?
body: <p>I have an ASP Search page, which on pageload calls the SearchValves function, even if there aren't any filters. This causes basically all of the records to return, which makes the page load take forever.  Is there anyway I can prevent the page from calling this function on pageLoad?  Here's the code: </p>
  
  <pre><code>&lt;asp:ObjectDataSource ID="ValvesDataSource" runat="server" SelectMethod="SearchValves"
      TypeName="ApexRemington.BLL.ValveWorkTicketBLL" SortParameterName="sortExpr"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:ControlParameter ControlID="CustomerID" Name="customer" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="WorkTicket" Name="workTicket" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="SalesOrder" Name="salesOrder" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="StartAddDate" Name="startAddDate" PropertyName="Text" Type="DateTime" /&gt;
          &lt;asp:ControlParameter ControlID="EndAddDate" Name="endAddDate" PropertyName="Text" Type="DateTime" /&gt;
          &lt;asp:ControlParameter ControlID="StartCompletionDate" Name="startCompletionDate" PropertyName="Text" Type="DateTime" /&gt;
          &lt;asp:ControlParameter ControlID="EndCompletionDate" Name="endCompletionDate" PropertyName="Text" Type="DateTime" /&gt;
          &lt;asp:ControlParameter ControlID="Area" Name="area" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="LocationDescription" Name="locationDescription" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="EquipmentProtected" Name="equipmentProtected" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="ValveSerial" Name="valveSerial" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="ValveNumber" Name="valveNumber" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="BasketNumber" Name="basketNumber" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="Manufacturer" Name="manufacturer" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="ValveModel" Name="valveModel" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="TypeList" Name="valveType" PropertyName="SelectedValue" Type="Object" /&gt;
          &lt;asp:ControlParameter ControlID="ValveSize" Name="valveSize" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="ValveRating" Name="valveRating" PropertyName="Text" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="SetPressure" Name="setPressure" PropertyName="Text" Type="String" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>The "SearchValves" function: </p>
  
  <pre><code>public static IEnumerable&lt;Valve&gt; SearchValves(
          string customer,
          string workTicket,
          string salesOrder,
          string area,
          string locationDescription,
          string equipmentProtected,
          DateTime? startAddDate,
          DateTime? endAddDate,
          DateTime? startCompletionDate,
          DateTime? endCompletionDate,
          string valveSerial,
          string valveNumber,
          string basketNumber,
          string manufacturer,
          string valveModel,
          ValveType? valveType,
          string valveSize,
          string valveRating,
          string setPressure,
          string sortExpr)
      {
          using (MiniProfiler.Current.Step("SearchValves"))
          using (var context = rempscoDataContext.CreateContext())
          {
              IQueryable&lt;valve_history&gt; data = context.valve_histories;
  
              var flag = false;
  
  
              bool valve_flag;
              var valve_filter = _BuildValveFilter(
                  customer,
                  valveSerial,
                  valveNumber,
                  basketNumber,
                  manufacturer,
                  valveModel,
                  valveType,
                  valveSize,
                  valveRating,
                  setPressure,
                  out valve_flag);
  
              data = data.Where(valve_filter);
              if (valve_flag)
                  flag = true;
  
              bool ticket_flag;
              bool only_store_flag;
              var ticket_filter = _BuildWorkTicketFilter(
                  customer,
                  workTicket,
                  null,
                  salesOrder,
                  startAddDate,
                  endAddDate,
                  startCompletionDate,
                  endCompletionDate,
                  area,
                  locationDescription,
                  equipmentProtected,
                  string.Empty,
                  string.Empty,
                  string.Empty,
                  out ticket_flag,
                  out only_store_flag);
  
              if (ticket_flag)
              {
                  data = data.WhereAny(v =&gt; v.valve_work_tickets, ticket_filter);
                  flag = true;
              }
  
              if (!flag)
              {
                  data = data.Where(v =&gt;
                      v.valve_work_tickets.Any(wt =&gt; Security.CurrentStores.Contains(wt.store.s_store_id)) &amp;&amp;
                      v.valve_work_tickets.Any(wt =&gt; wt.status == (char)ValveWorkTicketStatus.Invoiced));
              }
  
              var retData = (
                  from vh in data
                  group vh by vh.valve_id into vhgroups
                  let vhid = vhgroups.Max(x =&gt; x.history_id)
                  from vh in vhgroups
                  where vh.history_id == vhid
                  let v = vh.valve
                  select new Valve()
                  {
                      ValveID = v.valve_id,
                      Type = (ValveType)v.valve_type,
                      Manufacturer = v.manufacturer,
                      InternalValveNumber = v.internal_valve_number,
                      InternalBasketNumber = v.internal_basket_number,
                      SerialNumber = v.serial_number,
                      ModelNumber = v.model_number,
                      Size = v.size,
                      Temperature = v.temperature,
                      ConnectionType = v.connection_type,
                      LastServiceDate = v.last_service_date,
                      CustomerID = v.customer_id,
                      Comments = v.comments,
  
                      AddTime = v.add_time,
                      AddUser = v.add_user,
                      EditTime = v.edit_time,
                      EditUser = v.edit_user,
  
                      //PSV Specific Fields
                      TopType = v.top_type,
                      SetPressureType = v.set_pressure_type,
                      SetPressure = v.set_pressure,
                      Capacity = v.capactity,
                      InFlangeSize = v.in_flange_size,
                      OutFlangeSize = v.out_flange_size,
                      BackPressureType = v.back_pressure_type,
                      BackPressure = v.back_pressure,
                      CodeSymbol = v.code_symbol,
                      ColdSetPressureType = v.cold_set_pressure_type,
                      ColdSetPressure = v.cold_set_pressure,
                      CRNNumber = v.crn_number,
  
                      //API Specific Fields
                      Rating = v.rating,
                      BodyMaterial = v.body_material,
                      TrimMaterial = v.trim_material,
                      PartNumber = v.part_number,
                      APIValveType = v.api_valve_type,
  
                      WorkTickets = (from wt in v.valve_work_tickets
                                     select new ValveWorkTicket()
                                     {
                                         WorkTicketID = wt.work_ticket_id,
                                         Status = (ValveWorkTicketStatus)wt.status,
  
                                         FullWorkTicket = wt.store.s_store_id + '-' + wt.ticket_number,
  
                                         AddTime = wt.add_time,
  
                                         Customer = new Customer()
                                         {
                                             CustomerNumber = wt.customer.c_cust_id,
                                             Name = wt.customer.c_name,
                                         },
                                         SalesOrder = wt.order_id.HasValue ? new SalesOrder()
                                         {
                                             OrderID = wt.sales_order.order_id,
                                             FullOrder = wt.sales_order.store.s_store_id + '-' + wt.sales_order.order + '-' + wt.sales_order.order_ext,
                                         } : new SalesOrder() { FullOrder = string.Empty, OrderID = 0 },
                                     }).ToList(),
  
                      Customer = new Customer()
                      {
                          Name = v.customer.c_name,
                          CustomerNumber = v.customer.c_cust_id,
                      },
                  });
  
              retData = string.IsNullOrEmpty(sortExpr) ?
                  retData.OrderBy(v =&gt; v.SerialNumber) :
                  retData.OrderBy(sortExpr);
  
              return retData.ToList();
          }
      }
  </code></pre>
  
  <p>Currently the valve flag will return false and prevent data from returning if the search parameters are empty. Is there another way to accomplish this without actually calling the function on pageload?</p>