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

multiple controls, radwindow and ajax

4 Answers 81 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 18 Jan 2012, 12:01 PM
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?

4 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 20 Jan 2012, 06:00 PM
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
0
Roger
Top achievements
Rank 1
answered on 22 Jan 2012, 02:59 AM
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
0
Roger
Top achievements
Rank 1
answered on 22 Jan 2012, 03:36 AM
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?

0
Roger
Top achievements
Rank 1
answered on 22 Jan 2012, 07:43 AM
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.
Tags
Ajax
Asked by
Roger
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Roger
Top achievements
Rank 1
Share this question
or