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

[Solved] AjaxManager updating controls not defined declaratively

4 Answers 268 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Rob Heckart
Top achievements
Rank 1
Rob Heckart asked on 24 Jun 2008, 07:20 PM
Hi,

I'm having a problem that I can't seem to get around. I have a radGrid with names in it. Above it is a standard hyperlink that users will click on to filter the records using a radWindow. The grid fills using the NeedDataSource event.

The filter hyperlink fires a client-side javascript event:

function ShowFilter() 
    { 
      //Call existing global function to obtain a reference to the window manager 
      var oManager = GetRadWindowManager(); 
      //Show a particular existing window 
      oManager.open (null,"winFilter"); 
    } 

This works fine and opens the form. The user clicks on the appropriate filters and closes the window, which fires this function:

function FilterEmployees(radWindow) 
   var oValue = radWindow.argument; 
                 
   var ajaxManager = $find("<%= ampAssessment.ClientID %>"); 
   ajaxManager.ajaxRequest("Filter:" + oValue); 
               

This code correctly fires the radAjaxManager and passes the correct values to codebehind. The problem is that the radGrid with names is not in the declarative list of <AjaxSettings> to get updated. I have a section in the <AjaxSettings> that updates panels as a result of the AjaxManager ajaxRequest (I use the client-side calls for updating the panels when someone clicks on a name in the grid). However, I don't want to add the grid to the list of <UpdatedControls> because the grid is the control that starts the update in this case (client-side row selection fires a javascript routine).

What I want is when the ajaxRequest or Rebind is completed, the grid and only the grid will update. This is not currently happening and I've tried all sorts of client and server side code without success. Is there a way to programatically do this in the ajaxRequest or Rebind?

Rob

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 25 Jun 2008, 01:17 PM
Hello Rob,

Thank you for contacting us. You can take the following steps to achieve the desired effect:

1. On RadScriptManager_AjaxRequest check whether e.Argument is request for filtering in your particular example.
2. If this is true, add to RadAjaxManager.AjaxSettings RadAjaxManager as initiator of the request and RadGrid as updated control
3. Invoke the RadGrid.Rebind() method.

This way next time when you call RadAjaxManager.ajaxRequest on the client the code of 2 and 3  won't be executed.

Here is example how it looks on the server side:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)  
{  
 if (e.Argument.StartsWith("Filter"))  
 {  
  RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, RadGrid1);  
  RadGrid1.Rebind();  
 }  

and on the client side:
function startAjaxRequest()  
{  
 var ajaxManager  = $find("<%= RadAjaxManager1.ClientID %>");    
 //use Filter as a flag that the gird must be updated  
 ajaxManager.ajaxRequest("Filter:other options" );    

Best regards,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rob Heckart
Top achievements
Rank 1
answered on 26 Jun 2008, 02:15 PM
Hi Nikolay,

I did as you suggested - actually that's the way I had it set up at one point. In my client side Javascript, I have:

            function FilterEmployees(radWindow) 
            { 
                //debugger; 
                var oValue = radWindow.argument; 
                 
                var ajaxManager = $find("<%= ampAssessment.ClientID %>"); 
                ajaxManager.ajaxRequest("Filter:" + oValue); 
                 
            } 

ampAssessment is my radAjaxManager. On the codebehind, I have this code:

        Public Sub ampAssessment_AjaxRequest(ByVal sender As ObjectByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles ampAssessment.AjaxRequest 
 
            If Not e.Argument.Contains(":"Then 
 
                LoadPersonalData(e.Argument) 
                LoadLeadershipLevelTabStrip(e.Argument) 
 
                LoadCompetencyTree() 
 
                pnlLeadershipLevels.Enabled = True 
                pnlPersonalDetails.Enabled = True 
                'pnlTabStrips.Enabled = True 
                'pnlAssessmentDetails.Enabled = True 
 
            ElseIf e.Argument.Contains("Filter"Then ' We're filtering employees 
 
                strFilterLeadershipLevel = e.Argument.Replace("Filter:"String.Empty) 
 
                ampAssessment.AjaxSettings.AddAjaxSetting(ampAssessment, grdEmployees, lpAssessment) 
 
                grdEmployees.Rebind() 
 
            End If 
 
        End Sub 

Now, because of an error in my Linq query that doesn't create the T-SQL I want, the code below returns no records, which should result in an empty grid:

        Protected Sub grdEmployees_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdEmployees.NeedDataSource 
 
            If Profile.Organization.LeadershipLevel = "GRP" Then 
 
                Dim assessees = From emp In db.Employees _ 
                                 Where emp.DWEmployee.ORGUNIT_ID = Profile.Organization.OrgAbbreviation And _ 
                                 emp.DeletedBy Is Nothing And _ 
                                 emp.DWEmployee.PERSON_STATUS_CODE = "A" _ 
                                 Order By emp.DWEmployee.FULL_NAME _ 
                                 Select EmployeeName = emp.DWEmployee.FULL_NAME, _ 
                                        LeadershipLevel = emp.CurrentLeadershipLevel.Description, _ 
                                        emp.EmployeeID, _ 
                                        EmployeeGroup = emp.DWEmployee.ORGUNIT_ID, _ 
                                        NextLevel = emp.NextLevel.Description 
 
                If Not String.IsNullOrEmpty(strFilterLeadershipLevel) Then 
 
                    assessees = From emp In db.Employees _ 
                                     Where emp.DWEmployee.ORGUNIT_ID = Profile.Organization.OrgAbbreviation And _ 
                                     emp.DeletedBy Is Nothing And _ 
                                     emp.DWEmployee.PERSON_STATUS_CODE = "A" And _ 
                                     emp.CurrentLeadershipLevelID.ToString.Contains(strFilterLeadershipLevel) _ 
                                     Order By emp.DWEmployee.FULL_NAME _ 
                                     Select EmployeeName = emp.DWEmployee.FULL_NAME, _ 
                                            LeadershipLevel = emp.CurrentLeadershipLevel.Description, _ 
                                            emp.EmployeeID, _ 
                                            EmployeeGroup = emp.DWEmployee.ORGUNIT_ID, _ 
                                            NextLevel = emp.NextLevel.Description 
 
                End If 
 
                grdEmployees.DataSource = assessees 
 
                ' HACK: Take this out when security is made better 
            ElseIf Profile.Organization.LeadershipLevel = "BAE" Then 
 
                Dim assessees = From emp In db.Employees _ 
                                 Where emp.DeletedBy Is Nothing And _ 
                                 emp.DWEmployee.PERSON_STATUS_CODE = "A" _ 
                                Order By emp.DWEmployee.FULL_NAME _ 
                                Select EmployeeName = emp.DWEmployee.FULL_NAME, _ 
                                        LeadershipLevel = emp.CurrentLeadershipLevel.Description, _ 
                                        emp.EmployeeID, _ 
                                        EmployeeGroup = emp.DWEmployee.ORGUNIT_ID, _ 
                                        NextLevel = emp.NextLevel.Description 
 
                If Not String.IsNullOrEmpty(strFilterLeadershipLevel) Then 
 
                    assessees = From emp In db.Employees _ 
                                 Where emp.DeletedBy Is Nothing And _ 
                                 emp.DWEmployee.PERSON_STATUS_CODE = "A" And _ 
                                emp.CurrentLeadershipLevelID.ToString.Contains(strFilterLeadershipLevel) _ 
                                Order By emp.DWEmployee.FULL_NAME _ 
                                Select EmployeeName = emp.DWEmployee.FULL_NAME, _ 
                                        LeadershipLevel = emp.CurrentLeadershipLevel.Description, _ 
                                        emp.EmployeeID, _ 
                                        EmployeeGroup = emp.DWEmployee.ORGUNIT_ID, _ 
                                        NextLevel = emp.NextLevel.Description 
 
                End If 
 
                grdEmployees.DataSource = assessees 
 
                End If 
 
        End Sub 

I've debugged this and lines 35 and on are executing. Line 62 has assessees returning no results. This fires correctly after the ajaxRequest. Yet the grid does not update and shows all the previous records returned.

If I jump over to the browser while this code is executing, I can see my loading panel over the other areas that were setup declaratively, but not over grdEmployees.

Rob





0
Richard
Top achievements
Rank 1
answered on 26 Jun 2008, 07:46 PM
I would really appreciate some clarification on this.  Nikolay is advocating dynamically altering the AjaxSettings, however when I submitted a ticket on this in March I received the following response from Steve:

Currently dynamically altering the AjaxSettings in the Prometheus RadAjax controls is not supported. Due to various MS AJAX limitations and the way it works as whole, we cannot promise that such functionality will ever be supported (our devs have been investigating on that for months).

Has this issue been resolved so that the AjaxSettings can now be altered dynamically?

Thanks!
0
Nikolay Rusev
Telerik team
answered on 27 Jun 2008, 01:48 PM
Hi Richard,

Thank you for getting back yo us. I really can't find the problem in your code. For your convenience, I've prepared sample demo showing you what my general idea is. Please, give this suggestion a try and let me know how it goes and if any other questions arise.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Ajax
Asked by
Rob Heckart
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Rob Heckart
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Share this question
or