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

DotNetNuke, UserControl and RadAjaxManager

5 Answers 136 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 03 Oct 2011, 02:19 AM

I've been working on this issue all weeken and have read almost every post and demo related to the RadGrid and to the RadAjaxManager,  Hopefully I've posted enough informatio to get a clear understanding of my issue
I’m using a CommandItem Templete to add a new record to a grid with a custom form.  I have the “add new record” linkbutton working but I need some help with the grid refresh when the radWindow closes.  I'm using the sample that opens a radWindow and then passes back informtion to the parent form with the OnClientClose .  I’m also using DotNetNuke as my platform and I’ve creates a usercontrol for my module.  I would like the Grid to refresh when I close the radWindow that has the form.  I’m using the return to parent that is in one of the demos but I cannot get any type of grid refresh to work outside of calling a page reload.  It seems that the problem is in the fact that I need to programmatically add the radAjaxManager programmatically to the page.  I’ve tried using
Dim manager As New RadAjaxManager()
manager.ID = "RadAjaxManager1"
Me.Page.Form.Controls.Add(manager)

But if I try to immediately test it with
value = TryCast(Me.Page.Items(GetType(RadAjaxManager)), RadAjaxManager) I come back with nothing.

Also if I put

function refreshGrid(arg) {
                  if (!arg) {
                        var mgr = $find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>');
                               mgr.ajaxRequest("Refresh")
                                return false;       
                    }
        }
I get this error:
A critical error has occurred.Object reference not set to an instance of an object.
I have added:
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
 <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
           <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>

The bottom line is that I cannot get the RadAjaxManager1_AjaxRequest to fire so I can run   RadGrid1.MasterTableView.SortExpressions.Clear()
        RadGrid1.MasterTableView.GroupByExpressions.Clear()
        RadGrid1.Rebind()

I have added   window.location.reload(true); to the OnClientClose function and that refreshes the grid currently but that is not the smoothest way.  All help is appreciated.

Bill

5 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 03 Oct 2011, 04:57 AM
Hello William,

Try the following code for adding the RadAjaxManager:
protected void Page_Load(object sender, EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    if(manager == null)
    {
        manager = new RadAjaxManager();
        manager.ID = "RadAjaxManager1";
        this.Controls.Add(manager);
        this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager);
    }
}

Then on Page_Load add a setting where the manager updates the grid and attach handler for the AjaxRequest event.

Also, the script you have might not be avaluated properly. Try wrapping it into RadScriptBlock, or register it through the ScriptManager (calling the RegisterStartupScript(Page, typeof(Page),....) method).

Kind regards,
Iana Tsolova
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
William
Top achievements
Rank 1
answered on 03 Oct 2011, 01:43 PM
Thank you for your help.  I've added in the Page Load
Dim manager As RadAjaxManager = RadAjaxManager.GetCurrent(Page)
If manager Is Nothing Then
manager = New RadAjaxManager()
manager.ID = "RadAjaxManager1"
Me.Controls.Add(manager)
Me.Page.Items.Add(GetType(RadAjaxManager), manager) 

AddHandler manager.AjaxRequest, AddressOf manager_AjaxRequest

manager.AjaxSettings.AddAjaxSetting(manager, RadGrid1)
End If

But you have a suggestion of how to run:
function refreshGrid(arg) {
         alert('Hello World! refreshGrid');
         if (!arg) {
 
             var mgr = $find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>');
             mgr.ajaxRequest("rebind")
             $get("order").innerHTML = mgr.toString  + "Process completed";
             return false;
         }
     }


It seems thatvar mgr = $find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>'); comes back with nothing so it can not process the ajaxRequest.  Since this is a usercontrol I also have the RadAjaxManagerProxy on the usercontrol.  Should I remove that?

I think we are getting closer.

Thanks


0
Iana Tsolova
Telerik team
answered on 03 Oct 2011, 03:01 PM
Hello William,

Can you confirm that after adding the manager dynamically, you can successfully access it, on Page_PreRender for instance, using the RadAjaxManager.GetCurrent(Page) method?

All the best,
Iana Tsolova
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
William
Top achievements
Rank 1
answered on 03 Oct 2011, 03:07 PM
I added
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
     Try
         Dim manager As RadAjaxManager = RadAjaxManager.GetCurrent(Page)
         Response.Write(manager.ID.ToString + " is loaded")


And it comes back RadAjaxManager1 is loaded.  So that part I think should be fine.

Thanks for your help. 
0
William
Top achievements
Rank 1
answered on 04 Oct 2011, 02:38 AM
I changed
 var mgr = $find('<%=RadAjaxManager.GetCurrent(Page).ClientID %>');
mgr.ajaxRequest("Refresh")
return false;        

to var mgr = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("rebind");

And put it in the OnClientClose and it now is working.  
 function OnClientClose(oWnd, args) {
            var mgr = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("rebind");
         
            }
        }

Thanks for the help
Tags
Ajax
Asked by
William
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
William
Top achievements
Rank 1
Share this question
or