This is a migrated thread and some comments may be shown as answers.

EnableAutomaticLoadOnDemand re-fires on form submit?

2 Answers 47 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
msigman
Top achievements
Rank 2
msigman asked on 09 Nov 2010, 05:15 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Simon
Telerik team
answered on 15 Nov 2010, 05:05 PM
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
0
msigman
Top achievements
Rank 2
answered on 15 Nov 2010, 06:16 PM
Thank you for the detailed explanation and workaround!
Tags
Ajax
Asked by
msigman
Top achievements
Rank 2
Answers by
Simon
Telerik team
msigman
Top achievements
Rank 2
Share this question
or