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

Should the NeedDataSource event be fired by an AJAX request?

6 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 03 May 2017, 12:48 AM

Hi, I have a page that contains a RadComboBox that let's the user select a group name and a RadGrid that displays the members of the selected group.  I have added a setting to the RadAjaxManager to make the combo box update the grid.  That part seems to be working as the loading panel is shown over the grid each time I pick a different value from the combo box.  The problem is that the data in the grid doesn't change, unless I click the refresh button on the grid.

 

I set a breakpoint in my NeedDataSource event handler and I can see that the AJAX request occurs, but the handler is not invoked.  Is this the expected behavior?  If so, what is the correct way to achieve my desired outcome?

 

<telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
   <AjaxSettings>
     <telerik:AjaxSetting AjaxControlID="RadComboBoxCustomGroups2">
       <UpdatedControls>
         <telerik:AjaxUpdatedControl ControlID="RadGridGroupMembers" LoadingPanelID="RadAjaxLoadingPanel" />
       </UpdatedControls>
     </telerik:AjaxSetting>
  </AjaxSettings>
</telerik:RadAjaxManager>

 

<asp:Panel ID="CustomizeCustomGroupPanel" runat="server" GroupingText="Customize Custom Group" Width="635px">
  <div>
    <div class="InlineTable">
      <telerik:RadComboBox ID="RadComboBoxCustomGroups2" runat="server"
                           DataSourceID="SqlDataSourceCustomGroups" DataTextField="Group_Name"
                           DataValueField="Group_Id" CssClass="radcombobox" AutoPostBack="True" />
    </div>
  </div>
  <br />
  <div>
    <div>
      <telerik:RadGrid ID="RadGridGroupMembers" runat="server" CssClass="RadGrid_site" ClientSettings-Selecting-AllowRowSelect="true"
                       AutoGenerateColumns="false" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" OnNeedDataSource="RadGridGroupMembers_NeedDataSource"
                       OnUpdateCommand="RadGridGroupMembers_UpdateCommand" OnInsertCommand="RadGridGroupMembers_InsertCommand">
        <MasterTableView CommandItemDisplay="Top" EditMode="InPlace" DataKeyNames="Branch_Id">
          <Columns>
            <telerik:GridEditCommandColumn />
            <telerik:GridBoundColumn DataField="Branch_Id" HeaderText="Branch ID" UniqueName="Branch_Id" ReadOnly="true" Display="false">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Branch Name" UniqueName="Branch_Name">
              <EditItemTemplate>
                <asp:DropDownList runat="server" DataValueField="Branch_Name" DataSourceId="SqlDataSourceCustomGroupBranchesSource">
                </asp:DropDownList>
              </EditItemTemplate>
              <ItemTemplate>
                <asp:Label runat="server" ReadOnly="true" Text='<%# Eval("Branch_Name") %>'>
                </asp:Label>
              </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridDateTimeColumn DataField="Expiration" HeaderText="Expiration" UniqueName="Expiration" ReadOnly="false">
            </telerik:GridDateTimeColumn>
          </Columns>
        </MasterTableView>
      </telerik:RadGrid>
    </div>
  </div>
</asp:Panel>

6 Answers, 1 is accepted

Sort by
0
Craig
Top achievements
Rank 1
answered on 08 May 2017, 05:28 PM

Is anyone able to help?  I thought this would be a pretty straightforward question to answer.

0
Rumen
Telerik team
answered on 11 May 2017, 11:53 AM
Hi,

Please, review the following article on the topic: Advanced Data-binding (Using NeedDataSource Event).

The NeedDataSource event fires only in the following cases:

  • Immediately after On_Load if the grid has not yet been data-bound and there is no ViewState data. This means that if MasterTableViewEnableViewState has been set to False, the grid will bind each time the page loads, not only the first time.

  • When a paging operation occurs.

  • When a sorting operation occurs.

  • When an edit command is fired.

  • Immediately after any UpdateDelete, or Insert command event handlers finish execution. You can cancel these operations by handling the ItemCommand event and assigning True to  event argument's Canceled property.

  • When grouping or ungrouping, immediately after the GroupsChanging event occurs.

  • When filtering (choosing an option from a column filter menu).

  • When re-sorting a group.

  • When a call to the grid's Rebind method takes place.

  • Prior to binding any detail table.

  • Custom cases, for example using the RebindReason property as noted below.

Can you disable the AJAX and see whether your code works properly with ajax?

Regards,
Rumen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Craig
Top achievements
Rank 1
answered on 11 May 2017, 06:00 PM

Hi Rumen, thanks for your reply.  I assume that you meant to ask if the page works without AJAX and, yes, if I rebind the grid in the combobox's SelectedIndexChanged event handler.  However, the intent is to make the grid update without doing a full postback.

 

An AJAX call must be covered under one of the conditions under which NeedDataSource is fired, because the refresh button on the grid issues an AJAX request which triggers the NeedDataSource event.  I just need to know why the AJAX request issued by the AjaxManager does not.

 

0
Craig
Top achievements
Rank 1
answered on 11 May 2017, 07:22 PM

In case it's helpful, here are the request bodies, sans viewstate, for the requests which did and did not trigger NeedDataSource.  From what I can see, the main differences are that the request which didn't trigger NeedDataSource had the combobox as the event target and it supplied a value for the eventargument as well as including the RadAjaxControlID.

 

 

Request issue by clicking the refresh button on the grid.  This did trigger the NeedDataSource event:

 

   __ASYNCPOST: true
   __EVENTARGUMENT:
   __EVENTTARGET: ctl00%24MainContent%24RadPanelBarConfigs%24i0%24RadGridGroupMembers%24ctl00%24ctl02%24ctl00%24RebindGridButton
   __EVENTVALIDATION: %2FwEdAAu5qrhQv7ChEJsz9%2Bu33IY6%2BkWE8D8RA8MpejIyQ9aPWS23aN3xlq%2BQPo91erJ3%2BJdpPfQtHBM7%2BF4djGk%2Bh3Mz6sXmDN3R3tscL%2BKhTsFOvTnVSHz7LjPXOknSAuiI2q1BBflIkYJpVDHzuCw2kHwuD7XS7SX%2BlIJ2bks27UrqSMgPcUP7UAN6z9mzkaJy8xPLGOFSa1j9rfkiFX5v7uLt0LO0b%2B1O1eGoJp9LojK4EENASGygkxAiZA1nQcB67TfouOcuzaLfvUiaTFszjB7I
[...]
   __VIEWSTATEGENERATOR: 0FED1121
   BuildServicesRadScriptManager_TSM: %3B%3BSystem.Web.Extensions%2C%20Version%3D4.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D31bf3856ad364e35%3Aen-US%3Aab0488d2-2a95-4bc4-9f11-51ca4952d5f7%3Aea597d4b%3Ab25378d2%3BTelerik.Web.UI%2C%20Version%3D2016.3.1027.45%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D121fae78165ba3d4%3Aen-US%3A920f05c9-fad1-4469-a141-2ec21334873b%3A16e4e7cd%3A33715776%3Af7645509%3A24ee1bba%3Ae330518b%3A2003d0b8%3Ac128760b%3A88144a7a%3A1e771326%3Ac8618e41%3A1a73651d%3A333f8d94%3Af46195d3%3A4cacbc31%3A2a8622d7%3Aed16cbdc%3Aaa288e2d%3A258f1c72%3A58366029%3B
   ctl00%24BuildServicesRadScriptManager: ctl00%24MainContent%24RadPanelBarConfigs%24i0%24ctl00%24MainContent%24RadPanelBarConfigs%24i0%24RadGridGroupMembersPanel%7Cctl00%24MainContent%24RadPanelBarConfigs%24i0%24RadGridGroupMembers%24ctl00%24ctl02%24ctl00%24RebindGridButton
   ctl00%24MainContent%24RadPanelBarConfigs%24i0%24RadComboBoxCustomGroups2: Static%20Pri1
   ctl00_BuildServicesRadMenu_ClientState:
   ctl00_MainContent_RadPanelBarConfigs_ClientState: %7B%22expandedItems%22%3A%5B%220%22%5D%2C%22logEntries%22%3A%5B%5D%2C%22selectedItems%22%3A%5B%5D%7D
   ctl00_MainContent_RadPanelBarConfigs_i0_RadComboBoxCustomGroups2_ClientState: %7B%22logEntries%22%3A%5B%5D%2C%22value%22%3A%2228%22%2C%22text%22%3A%22Static%20Pri1%22%2C%22enabled%22%3Atrue%2C%22checkedIndices%22%3A%5B%5D%2C%22checkedItemsTextOverflows%22%3Afalse%7D
   ctl00_MainContent_RadPanelBarConfigs_i0_RadGridGroupMembers_ClientState:

 

 

Request issued by selecting a new value from the combobox.  This did NOT trigger the NeedDataSource event:

 

   __ASYNCPOST: true
   __EVENTARGUMENT: %7B%22Command%22%3A%22Select%22%2C%22Index%22%3A2%7D
   __EVENTTARGET: ctl00%24MainContent%24RadPanelBarConfigs%24i0%24RadComboBoxCustomGroups2
   __EVENTVALIDATION: %2FwEdAAv4knWqsX%2F8HlNofBCTCjJy%2BkWE8D8RA8MpejIyQ9aPWS23aN3xlq%2BQPo91erJ3%2BJdpPfQtHBM7%2BF4djGk%2Bh3Mz6sXmDN3R3tscL%2BKhTsFOvTnVSHz7LjPXOknSAuiI2q1BBflIkYJpVDHzuCw2kHwuD7XS7SX%2BlIJ2bks27UrqSMgPcUP7UAN6z9mzkaJy8xPLGOFSa1j9rfkiFX5v7uLt0LO0b%2B1O1eGoJp9LojK4EGtssa5d2fcmpPfxhlyglJvZuNmP08dWtLxPf5%2FYxEhV
[...]
   __VIEWSTATEGENERATOR: 0FED1121
   BuildServicesRadScriptManager_TSM: %3B%3BSystem.Web.Extensions%2C%20Version%3D4.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D31bf3856ad364e35%3Aen-US%3Aab0488d2-2a95-4bc4-9f11-51ca4952d5f7%3Aea597d4b%3Ab25378d2%3BTelerik.Web.UI%2C%20Version%3D2016.3.1027.45%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D121fae78165ba3d4%3Aen-US%3A920f05c9-fad1-4469-a141-2ec21334873b%3A16e4e7cd%3A33715776%3Af7645509%3A24ee1bba%3Ae330518b%3A2003d0b8%3Ac128760b%3A88144a7a%3A1e771326%3Ac8618e41%3A1a73651d%3A333f8d94%3Af46195d3%3A4cacbc31%3A2a8622d7%3Aed16cbdc%3Aaa288e2d%3A258f1c72%3A58366029%3B
   ctl00%24BuildServicesRadScriptManager: ctl00%24BuildServicesRadScriptManager%7Cctl00%24MainContent%24RadPanelBarConfigs%24i0%24RadComboBoxCustomGroups2
   ctl00%24MainContent%24RadPanelBarConfigs%24i0%24RadComboBoxCustomGroups2: Static%20Pri1
   ctl00_BuildServicesRadMenu_ClientState:
   ctl00_MainContent_RadPanelBarConfigs_ClientState: %7B%22expandedItems%22%3A%5B%220%22%5D%2C%22logEntries%22%3A%5B%5D%2C%22selectedItems%22%3A%5B%5D%7D
   ctl00_MainContent_RadPanelBarConfigs_i0_RadComboBoxCustomGroups2_ClientState: %7B%22logEntries%22%3A%5B%5D%2C%22value%22%3A%2228%22%2C%22text%22%3A%22Static%20Pri1%22%2C%22enabled%22%3Atrue%2C%22checkedIndices%22%3A%5B%5D%2C%22checkedItemsTextOverflows%22%3Afalse%7D
   ctl00_MainContent_RadPanelBarConfigs_i0_RadGridGroupMembers_ClientState:
   RadAJAXControlID: ctl00_MainContent_RadPanelBarConfigs_i0_RadAjaxManager

 

0
Rumen
Telerik team
answered on 16 May 2017, 02:19 PM
Hello,

I want to share the following ideas:
- put the combobox in an update panel
- or update the whole panel
- or use the third approach to call the Rebind() method.

Regards,
Rumen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Craig
Top achievements
Rank 1
answered on 17 May 2017, 01:31 AM

Thanks Rumen.  I was able to get the grid to update with a combination of wrapping the grid in an asp:UpdatePanel and calling the grid's rebind method in the RadAjaxManager_AjaxRequest method.

 

I still don't understand why all of this is necessary.  The refresh button on the grid does the right thing without needing the grid to be in an update panel.

Tags
Grid
Asked by
Craig
Top achievements
Rank 1
Answers by
Craig
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or