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

GetCurrent always returns null

10 Answers 484 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Joshua Gates
Top achievements
Rank 1
Joshua Gates asked on 21 Nov 2007, 04:32 PM
    I have apage with an RadAjaxManager on it.. in my web user control I attempt to get set the RadAjaxManager variable using the RadAjaxManager.GetCurrent so that i can initiate an ajax postback with javascript when a radwindow closes...

?

10 Answers, 1 is accepted

Sort by
0
Jason Maronge
Top achievements
Rank 1
answered on 21 Nov 2007, 09:35 PM
Joshua,

  I too have had issues with the GetCurrent.  I just stuck the following code in a helper class I have.  Here is what I came up with to help:

        public static RadAjaxManager GetCurrentAjaxManager(Page page)  
        {  
            if (page == null)  
                throw new ArgumentNullException("page is null");  
 
            if (page.Master != null)  
                return FindControl<RadAjaxManager>(page.Master.Controls);  
            else 
                return FindControl<RadAjaxManager>(page.Controls);  
        }  
 
        public static T FindControl<T>(ControlCollection Controls) where T : class 
        {  
            T found = default(T);  
 
            if (Controls != null && Controls.Count > 0)  
            {  
                for (int i = 0; i < Controls.Count; i++)  
                {  
                    if (found != nullbreak;  
 
                    found = Controls[i] as T;  
 
                    if (found != null)  
                    {  
                        break;  
                    }  
 
                    else 
 
                        found = FindControl<T>(Controls[i].Controls);  
                }  
            }  
 
            return found;  
        } 

Hopefully it can help you with your problem...

Jason
0
Matthew
Top achievements
Rank 1
answered on 31 Mar 2008, 01:07 AM
This doesn't work either. 

Create a master page.  Put a rad ajax manager on it. Create a content page.  This code, as referenced in all of Telerik's examples, 

Telerik.Web.UI.

RadAjaxManager.GetCurrent(this)

returns null every single time.  wtf? 

0
Maria Ilieva
Telerik team
answered on 31 Mar 2008, 10:31 AM
Hi Matthew,

Please refer to the following online example, which elaborates on this matter and to this forum post.

Regards,
Maria Ilieva
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Matthew
Top achievements
Rank 1
answered on 31 Mar 2008, 12:57 PM
"Hi Matthew,

Please refer to the following online example, which elaborates on this matter and to this forum post.

Regards,
Maria Ilieva
the Telerik team "

Yes, that example does NOT work.  The declarative code works fine in the HTML.  However, the code-behind "RadAjaxManager.GetCurrent(this).Alert("1");" doesn't!  This is why people are posting examples of code such as this:

"I too have had issues with the GetCurrent.  I just stuck the following code in a helper class I have.  Here is what I came up with to help: "
0
Vlad
Telerik team
answered on 31 Mar 2008, 01:10 PM
Hi Matthew,

I have attached small example to illustrate you how to use GetCurrent().You can use the method in any page stage except Init.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bent
Top achievements
Rank 2
answered on 16 Dec 2008, 11:26 PM
Hi there

I don't know if everyone solved their problems, but I had the same issue when I realised that it's the order of the controls that makes the difference!

I had placed the RadAjaxManager BEFORE the RadScriptManager, which for (possibly obvoius reasons) didn't work.
When I switched the controls, everyone was happy...

This is a somehow missed point in the documentation (or perhaps I'm just not thorough enough ;) )
0
gunther
Top achievements
Rank 1
answered on 13 Nov 2009, 06:10 PM
"I had placed the RadAjaxManager BEFORE the RadScriptManager, which for (possibly obvoius reasons) didn't work.
When I switched the controls, everyone was happy..."

just posting to say that kenneth's solution worked perfectly for me.  swapped the blocks so the scriptmanager came before the ajaxmanager in the markup and everyone was indeed happy.
0
Chris
Top achievements
Rank 1
answered on 21 Jul 2010, 03:38 AM
Thanks Kenneth, this was getting me frustrated. I'm so glad I stumbled on your solution.
0
jaime
Top achievements
Rank 1
answered on 02 Dec 2012, 04:24 PM
is correct your suggest. Thanx gunther
0
Aaron
Top achievements
Rank 1
answered on 08 May 2013, 07:05 PM
I just want to say thanks to Bent (maybe previously Kenneth?).  I have spent countless days working on this, and it to find the solution buried in a thread that had nothing to do with my original issue.  If this isn't in the documentation it should be. And for good measure, if it is somewhere in the documentation, it really needs to also be in big bold font on the "RadAjax and MasterPage How To" article.  This was causing ALL of my RadAjaxMangerProxy controls to do Nothing, but my RadAjaxPanels worked fine (just not my ideal solution because of page structure). It wasn't until i tried to dynamically 'Ajaxify' in code behind that I got the null issue.
Tags
Ajax
Asked by
Joshua Gates
Top achievements
Rank 1
Answers by
Jason Maronge
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Maria Ilieva
Telerik team
Vlad
Telerik team
Bent
Top achievements
Rank 2
gunther
Top achievements
Rank 1
Chris
Top achievements
Rank 1
jaime
Top achievements
Rank 1
Aaron
Top achievements
Rank 1
Share this question
or