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

No way to determine when control will be updated in requestStart

1 Answer 59 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jessica
Top achievements
Rank 1
Jessica asked on 09 Jun 2015, 09:32 AM

Hallo, sorry for my english.

I need to determine when control(panel) will be updated by radajaxmanager in theyrs onRequestStart. I need this to call kendo.destroy before postback to destroy existing kendo controls.

Problem is that objects, recieved from get_ajaxSettings have property with ClientID's of controls (InitControlID) and get_eventTarget returns uniqueId. Because of that, i cannot get controls that will be updated from settings collection for current request.

I've found _postbackControlClientID in ajax setting object, but that property contains invalid id, not like in InitControlID, but very similar.

Seems like there is no way to determine in onRequestStart event controls that will be updated.

So, that will be great if telerik developers add a function to onRequestStart eventArgs like get_currentAjaxSetting for situations like this.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 12 Jun 2015, 07:28 AM
Hello Jessica,

The client-side AJAX settings collection will contain information about the ClientID of the controls, because those are the IDs generated for the controls with ClientIDMode "AutoID". However, once you have the generated ClientID of the control you can easily split that ID by "_" and the last part will be the ID of the control. Furthermore, if you have more complex structure and the target control is nested control, you may have to find the wrapping AJAX panel, so you can find the ID of the control in the AJAX settings.

For your convenience, following is an example for retrieving the IDs of all updated controls:
<telerik:RadWindow runat="server" ID="RadWindow1" VisibleOnPageLoad="true" Width="800px" Height="300px">
    <ContentTemplate>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                function requestStart(sender, args) {
                    var ajaxControlClientID = getAjaxContainer(args.EventTargetElement);
                    var ajaxSettings = sender.get_ajaxSettings();
                    var controlsThatWillBeUpdated = [];
 
                    for (var i = 0; i < ajaxSettings.length; i++) {
                        if (ajaxSettings[i].InitControlID == ajaxControlClientID) {
                            var updatedControls = ajaxSettings[i].UpdatedControls;
                            for (var z = 0; z < updatedControls.length; z++) {
                                var cleanID = getCleanID(updatedControls[z].ControlID);
                                controlsThatWillBeUpdated.push(cleanID);
                            }
                        }
                    }
 
                    alert(controlsThatWillBeUpdated.toString());
                }
 
                function getAjaxContainer(element) {
                    while (element.className.indexOf("RadAjaxPanel") < 0) {
                        element = element.parentElement;
                    }
 
                    return element.children[0].id;
                }
 
                function getCleanID(id) {
                    var splitID = id.split("_");
                    return splitID[splitID.length - 1];
                }
            </script>
        </telerik:RadCodeBlock>
 
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
            <ClientEvents OnRequestStart="requestStart" />
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="Wrapper1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Wrapper1" />
                        <telerik:AjaxUpdatedControl ControlID="Panel1" />
                        <telerik:AjaxUpdatedControl ControlID="Panel2" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="Wrapper2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Wrapper2" />
                        <telerik:AjaxUpdatedControl ControlID="Panel3" />
                        <telerik:AjaxUpdatedControl ControlID="Panel4" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
 
        <asp:Panel runat="server" ID="Wrapper1">
            <asp:Button runat="server" ID="Button1" Text="Update panel 1 & 2" />
        </asp:Panel>
        <asp:Panel runat="server" ID="Panel1">panel1</asp:Panel>
        <asp:Panel runat="server" ID="Panel2">panel1</asp:Panel>
 
        <asp:Panel runat="server" ID="Wrapper2">
            <asp:Button runat="server" ID="Button2" Text="Update panel 3 & 4" />
        </asp:Panel>
        <asp:Panel runat="server" ID="Panel3">panel3</asp:Panel>
        <asp:Panel runat="server" ID="Panel4">panel4</asp:Panel>
    </ContentTemplate>
</telerik:RadWindow>

Hope this helps.



Regards,
Konstantin Dikov
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Ajax
Asked by
Jessica
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or