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

[Solved] RadAjaxManager and Radscriptmanager in code behind

3 Answers 357 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
PeterVV
Top achievements
Rank 1
PeterVV asked on 05 Feb 2010, 11:04 AM
Code below will fail because the RadAjaxManager won't be found (RadAjaxManager.GetCurrent returns null). The handler won't be added. However when I place the RadScriptManager component on the form in stead of creating it in the Code behind everything runs fine. (The RadAjaxManager is placed on the form)

How can I make it in such a way that it will also work when creating the RadScriptManager in the codebehind

    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
 
        Dim _ScriptManager As RadScriptManager  
        _ScriptManager = New RadScriptManager  
        _ScriptManager.ID = "ScriptManager" 
        _ScriptManager.EnablePageMethods = True 
        Form.Controls.AddAt(0, _ScriptManager)  
 
        If RadAjaxManager.GetCurrent(Me.Page) IsNot Nothing Then 
            AddHandler RadAjaxManager.GetCurrent(Me.Page).AjaxRequest, AddressOf HandledRadAjaxRequest  
        End If 
 
    End Sub 
 


3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 10 Feb 2010, 12:49 PM
Hello PeterVV,

Please try creating the ScriptManager on Page_Init instead of on Page_Load and see if it makes any difference.

Kind regards,
Iana
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
PeterVV
Top achievements
Rank 1
answered on 10 Feb 2010, 01:37 PM
When creating the scriptmanager in the the Page_Init does not change this behavoir. The handler still won't be set because RadAjaxManager.GetCurrent returns nothing. Having a look at the (form) controls during runtime shows that the scriptmanager is the first control in the collection and the ajaxmanager the 3th one (in my example).

Setting the handler somewhere else (Page_LoadComplete for example) doesn't change the behavoir. the handler won't be set.

The Idea behind this is to create the scriptmanager object automatically in a 'BasePageClass' so there is no need anymore to add it on the (inherited) forms.
0
Accepted
Iana Tsolova
Telerik team
answered on 12 Feb 2010, 10:11 AM
Hi PeterVV,

I followed your scenario and was able to replicate the problem. It seems that when the ScriptManager is created dynamically, you need to create the RadAjaxManager on Page_Init as well.
I prepared a sample project illustrating the suggested solution.
Please give it a try and let me know if it works for you.

Kind regards,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Ajax
Asked by
PeterVV
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
PeterVV
Top achievements
Rank 1
Share this question
or