multiple controls, radwindow and ajax

5 posts, 0 answers
  1. Roger
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 18 Jan 2012 Link to this post

    Hi,
    I have multiple controls (2 grids, 1 treview) with all of them opening separate radwindows via javascript to enter information. The radwindow saves the information and when it closes runs a callback javascript function that uses an ajaxrequest to reload the controls. Now all three use the ajaxrequest and according to the argument passed, the appropriate control is updated. On the page though, all three controls are added to the radajaxmanager list under the ajaxsetting for the ajaxmanager. So all three get updated when only 1 does.

    Is there a way to separate this out so that only the control affected will be updated?

  2. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 20 Jan 2012 Link to this post

    Hello Roger,

    You could achieve your scenario by using the ajaxRequestWithTarget(eventTarget, eventArgument) where the eventTarget is the UniqueID of the control and changing the RadAjaxManager AjaxSetting so the AjaxControlID to be the id of the updated control. I have assembled a sample code below for your reference:

    <telerik:RadScriptBlock runat="server">
        <script>
            function refreshRadGrid1()
            {
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequestWithTarget("<%= RadGrid1.UniqueID %>", "RadGrid1Update");
            }
        </script>
    </telerik:RadScriptBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadTreeView1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadTreeView1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

    Additionally, you could go through the help article below for more information on the topic.

    http://www.telerik.com/help/aspnet-ajax/ajax-ajaxmanager.html 

    Greetings,
    Antonio Stoilkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. Roger
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 21 Jan 2012 Link to this post

    Hi Antonio,
    the solution looks good but according to the documentation the ajaxRequestWithTarget emulates a callback from the designated control. This then bypasses the ajaxrequest. If it was a button then it would fire the onclick event of the button so I need to know what iss the default event of a grid and a treeview. Currently I just get a page refresh, neither the grid or treeview is refreshed.
    Regards
    Roger
  4. Roger
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 21 Jan 2012 Link to this post

    I have since found that I don't need to use ajax to go back to the server and refresh the grids.
    I can use:

    $find(
    "<%=RadGrid1.ClientID %>").get_masterTableView().rebind()

    now how can I do this with the treeview...it doesn't seem to have a rebind method?

  5. Roger
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 22 Jan 2012 Link to this post

    Hi Antonio,

    found the solution...you pointed me in the right direction.
    When I close the add/edit radwindow I do the ajaxRequestWithTarget call:
    var ajaxManager = $find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>');
                    ajaxManager.ajaxRequestWithTarget("<%= tvJobs.UniqueID %>", 'refreshTree');

    Now in the code, I set up a raisepostbackevent override:


    Protected Overrides Sub RaisePostBackEvent(sourceControl As IPostBackEventHandler, eventArgument As String)
            Dim bOverride As Boolean = True
            If TypeOf sourceControl Is Telerik.Web.UI.RadTreeView Then
                If CType(sourceControl, RadTreeView).UniqueID = Page.Request.Params("__EVENTTARGET") And eventArgument = "refreshTree" Then
                    Me.tvJobs.DataSource = MyDatasource
                    Me.tvJobs.DataBind()
                    Me.tvJobs.ExpandAllNodes()
                    bOverride = False
                End If
            End If
            If bOverride Then
                MyBase.RaisePostBackEvent(sourceControl, eventArgument)
            End If
        End Sub
    I suppose this could be done prettier but it does what I want. Now the grid refreshes via ajax for the external window call.
    If I don't bypass the MyBase.RaisePostBackEvent for my call then I get a "invalid json primitive" error.

    Now everything works.
Back to Top