EnableAutomaticLoadOnDemand re-fires on form submit?

3 posts, 1 answers
  1. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 09 Nov 2010 Link to this post

    I have a simple form with several dropdowns and a Submit button.  I set EnableAutomaticLoadOnDemand="true" on the dropdowns and set the data source in the codebehind like this:

    RadComboBox1.DataSource = Context.GetItems()

    But I do not call DataBind().

    GetItems() is a simple LINQ query that returns an IQueryable.  This is an example:
    sch = from h in Context.LktSchoolYearOutcomesENT
                          where !h.Deleted
                          orderby h.LkSchoolYearOutcomeENT.SchoolYearOutcome ascending
                          select new NameValuePair
                          {
                              Name = h.LkSchoolYearOutcomeENT.SchoolYearOutcome,
                              Value = h.LkSchoolYearOutcomeENT.OutcomeId
                          };


    When I load the page, submit the form, or click on one of the dropsdowns, every single dropdown does a round trip SELECT from the data source before submitting.  Why is this? 
  2. Answer
    Simon
    Admin
    Simon avatar
    2281 posts

    Posted 15 Nov 2010 Link to this post

    Hi msigman,

    RadComboBox does not do anything specific in this case, i.e. it does not iterate through the result returned by GetItems unless the request is a callback and the control's EnableAutomaticLoadOnDemand property is set to true. You can set the property to false and see the same effect.

    What is more, if you test the exact same setup with a DropDownList control, the same will happen. Even the first page load hits the database.

    This stems from the OnLoad method of the DataBoundControl, which we and all data bound ASP.NET controls inherit.

    You can test with the following code:
    class DropDownListNoOnLoad : DropDownList
    {
        protected override void OnLoad(EventArgs e)
        {
            //base.OnLoad(e);
        }
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        var ddl = new DropDownListNoOnLoad();
        ddl.ID = "ddl1";
        ddl.DataTextField = "ContactName";
     
        Form.Controls.Add(ddl);
     
        ddl.DataSource = GetResults();
    }
     
    protected IQueryable GetResults()
    {
        var results = from h in new LinqToSql.NorthwindDataContext().Customers
                      select new
                      {
                            ContactName = h.ContactName
                      };
     
        return results;
    }

    As a workaround to this you can set the DataSource property only during callback requests sent by the corresponding RadComboBox:
    RadComboBox.UniqueID.Equals(postCollection["__CALLBACKID"])

    I hope this helps.

    Regards,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 15 Nov 2010 Link to this post

    Thank you for the detailed explanation and workaround!
Back to Top