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

Programmatically Adding AjaxSettings to RadAjaxManager

7 Answers 607 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 09 Apr 2009, 01:42 PM
I have a couple of questions, but first let me explain my situation. I have a web page with multiple user controls. Three of these user controls contain a RadGrid embedded in them. I would like to use the RadAjaxManager with each of theses grids. So, I have a RadAjaxManager embedded directly on my main page. In order to add AjaxSettings for each of these grids I store the RadAjaxManager in the Session collection and reference it on the Page_Load event of each User Control in order to add the AjaxSetting for the embedded grid.

Here's an example of one of the grids:

        protected void Page_Load(object sender, EventArgs e) 
        { 
                ((RadAjaxManager)Session[Main.RadAjaxManagerKey]).AjaxSettings.AddAjaxSetting(radGrid, radGrid, RadAjaxLoadingDetailPanel); 
        } 

Where when the radGrid executes an AJAX callback it should update itself using the RadAjaxLoadingDetailPanel.

Now this executes a callback the first time. Every proceeding time, however, a postback is executed. Is there any obvious reason as to why this would be happening?

Also, if (the first time) I click the a column header for the radGrid it does a callback to sort the columns and updates itself. If I click a row it also does a callback, but what I'd really like is for it to do a postback on a row click and a callback on a column header click. I know why it does this currently: every postback for the radGrid is turned into a callback. Is there anyway to specifically limit which functions perform callbacks and which ones perform postbacks?

I really need help with these two issues. Without using the AJAX manager my grid functions in the desired manner, but I don't get a "LOADING" gif for non-postback functions (sorting for example) so the user is uncertain if any action is occurring.

Any solutions to these problems would be appreciated. Thanks.

7 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 13 Apr 2009, 01:21 PM

Hello Andrew,

This is indeed a strange issue and unfortunately I cannot say for certain what might be the exact cause of it. Does using RadAjaxManagerProxy to define the ajax settings inside the user controls declaratively (see this demo for details) makes a difference? Thus you will be able to define the same settings and specify a loading panel to be displayed during ajax requests initiated from each grid.

To perform plain postback on grid row click as opposed to ajax request on other actions, consider the following steps:

  1. Set ClientSettings -> EnablePostbackOnRowClick = true for the grid
  2. Intercept the OnRowClick client event of the control and raise a flag (using boolean javascript variable that this event was fired)
  3. Hook the OnRequestStart event of RadAjaxManager, check whether the flag is raised inside its handler and disable the ajax explicitly for this particular request in the following manner:

        <script type="text/javascript">  
            var flag = false;  
     
            function OnRequestStart(sender, args)  
            {  
               if(flag)  
               {  
                args.set_enableAjax(false);  
               }  
            }  
            function RowClick(sender, eventArgs)  
            {  
               flag = true;   
            }  
        </script> 

Best regards,

Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Andrew
Top achievements
Rank 1
answered on 13 Apr 2009, 06:51 PM
This works now for some of my controls, but the ones that require a server side event handler for the OnAjaxRequest event of the RadAjaxManager do not. For some reason, now, that event handler in the code behind never gets hit.
0
Sebastian
Telerik team
answered on 14 Apr 2009, 08:06 AM
Hello Andrew,

The OnAjaxRequest event handler will not be hit in case you explicitly disabled the ajax on row click using the approach from my previous reply. Is this the case? If the configuration is different, I will appreciate if you post the code related to the ajax manager and its requests (using the 'Format Code Block' dialog at the top right corner of the forum editor) in this thread.

Thus I will examine it in detail and will get back to you with more info on the subject.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Andrew
Top achievements
Rank 1
answered on 16 Apr 2009, 02:41 PM
This current issue is in a completely different grid on which I have disabled sorting. It is creating inits own user control like so:

<telerik:RadAjaxManagerProxy ID="AjaxManagerProxy" runat="server"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="radGrid"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="radGrid" LoadingPanelID="RadAjaxLoadingDetailPanel"/> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingDetailPanel" runat="server"
    <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' 
        style="border: 0;" /> 
</telerik:RadAjaxLoadingPanel> 
<telerik:RadGrid ID="radGrid" runat="server" AutoGenerateColumns="False" GridLines="None" 
    Width="200" Height="55px" Skin="Telerik" OnInsertCommand="radGrid_OnInsertCommand" 
    OnItemInserted="radGrid_OnItemInserted" OnItemEvent="radGrid_OnItemEvent" AllowSorting="false"
    <MasterTableView> 
        <RowIndicatorColumn Visible="False"
            <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn Visible="False" Resizable="False"
            <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
        <EditFormSettings> 
            <PopUpSettings ScrollBars="None"></PopUpSettings> 
        </EditFormSettings> 
    </MasterTableView> 
    <ClientSettings > </ClientSettings> 
</telerik:RadGrid> 

and its columns are generated via a template. In the first column of each row is an asp:Image control that is defined as follows:

<img src="addDeatilButton.png" onclick="AddDetailRowButtonClicked(<controlID>); return false;" onmouseover="this.style.cursor = 'pointer';" /> 

When this button is clicked I want to be able to do an AJAX update for the grid to add  X number of rows to the data source to which the grid is currently bound and then rebind it, where X is a parameter passed in from the client, a value contained in a RadNumericTextBox. Since the control is added via a template class the <controlID> will be hardcoded using the image.ClientID property.

The javascript function the button's onclick property refers to is defined as follows:

function AddDetailRowButtonClicked(id) 
    alert("AddDetailRowButtonClicked - " + id); 
    //var ajaxManager = $find("<%= RadAjaxManager.ClientID %>");  
    //ajaxManager.ajaxRequest(RadNumericTextBoxes(id)[0].get_editValue());  

As you can see, all I want it to do right now is throw up a message box displaying the calling control's id. But the RadAjaxManager still decides to go ahead and perform an AJAX update, which reloads the grid control without really changing anything. You can see by the code commented out that I want to call the control's server-side event handler with the value of the matching RadNumericTextBox. As I stated in my initial post this method worked when I had the RadAjaxManager embedded solely in the control which implements these custom image buttons. I'm not sure why this new way has caused it to stop working.

So, why does the RadAjaxManger do an update when no Callback or Postback has yet been performed?

Thank you.



0
Sebastian
Telerik team
answered on 17 Apr 2009, 03:45 PM
Hello Andrew,

Thank you for the detailed explanation. Unfortunately from the information provided so far I am not able to determine the exact reason for the abnormality in your particular case. To progress in our investigation, I would request you prepare a stripped working version of your project and send it enclosed to a regular support ticket. Thus we will examine your complete code implementation in detail and will get back to you with our findings.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andrew
Top achievements
Rank 1
answered on 17 Apr 2009, 03:52 PM
I will definitely attempt to do that, but it probably won't be until early next week.

Thanks again.
0
Sebastian
Telerik team
answered on 17 Apr 2009, 04:07 PM
Hi Andrew,

We will be expecting your example once you are ready with it.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Ajax
Asked by
Andrew
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or