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

Using the RadAjaxManagerProxy inside a WebUserControl

4 Answers 75 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
max
Top achievements
Rank 1
max asked on 11 Feb 2009, 11:35 AM
Hi, I'm populating a page dynamically with usercontrols, the user control is loaded without problem but the ajaxrequest or a simple postback inside the user conteol is not working..

This is an simple exsample....what's wrong with that?

ASPX:

        <asp:ScriptManager ID="ScriptManager1" runat="server">  
        </asp:ScriptManager> 
 
        <asp:Button ID="Button1" runat="server" Text="Button" /> 
 
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
          
        <asp:Button ID="Button2" runat="server" Text="Load WebUserControl" /> 
          
    <asp:Panel ID="Panel1" runat="server">  
    </asp:Panel> 
 
        <Telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
            <AjaxSettings> 
                <Telerik:AjaxSetting AjaxControlID="Button1">  
                    <UpdatedControls> 
                        <Telerik:AjaxUpdatedControl ControlID="Label1" /> 
                    </UpdatedControls> 
                </Telerik:AjaxSetting> 
            </AjaxSettings> 
        </Telerik:RadAjaxManager> 

ASPX VB

 
    Private Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click  
        Label1.Text = DateTime.Now.ToString()  
    End Sub 
 
    Private Sub Button2_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button2.Click  
        'Panel1.Controls.Add(LoadControl("WebUserControl1.ascx"))  
        LoadUserControl("WebUserControl1.ascx")  
    End Sub 
 
 
    Public Sub LoadUserControl(ByVal controlName As String)  
        If Not (LatestLoadedControlName Is NothingThen 
            Dim previousControl As Control = Panel1.FindControl(LatestLoadedControlName.Split("."c)(0))  
            If Not (previousControl Is NothingThen 
                Me.Panel1.Controls.Remove(previousControl)  
            End If 
        End If 
        Dim userControlID As String = controlName.Split("."c)(0)  
        Dim targetControl As Control = Panel1.FindControl(userControlID)  
        If targetControl Is Nothing Then 
            Dim userControl As UserControl = CType(Me.LoadControl(controlName), UserControl)  
            'slashes and tildes are forbidden  
            userControl.ID = userControlID.Replace("/""").Replace("~""")  
            Me.Panel1.Controls.Add(userControl)  
            LatestLoadedControlName = controlName  
        End If 
    End Sub 
 
 
    Private Property LatestLoadedControlName() As String 
        Get 
            Return CStr(ViewState("LatestLoadedControlName"))  
        End Get 
        Set(ByVal value As String)  
            ViewState("LatestLoadedControlName") = value  
        End Set 
    End Property 
 

ASCX

<asp:Button ID="Button1" runat="server" Text="Button" /> 
 
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
 
<telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">  
    <AjaxSettings> 
        <Telerik:AjaxSetting AjaxControlID="Button1">  
            <UpdatedControls> 
                <Telerik:AjaxUpdatedControl ControlID="Label1" /> 
            </UpdatedControls> 
        </Telerik:AjaxSetting> 
    </AjaxSettings> 
</Telerik:RadAjaxManagerProxy> 
 

ASCX VB

    Private Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click  
 
        Label1.Text = DateTime.Now.ToString()  
 
    End Sub 

4 Answers, 1 is accepted

Sort by
0
SamJ
Top achievements
Rank 1
answered on 11 Feb 2009, 11:58 AM
Hi max,

Try adding the ajax settings for the user control dynamically, on Page_PreRender event of the user control:

Protected Sub Page_PreRender(sender As Object, e As EventArgs) 
    Dim manager As RadAjaxManager = RadAjaxManager.GetCurrent(Page) 
    manager.AjaxSettings.AddAjaxSetting(Button1, Label1) 
End Sub 

Let me know if this works in your case.

Thanks,
SamJ
0
max
Top achievements
Rank 1
answered on 11 Feb 2009, 01:47 PM
It doesn't work..
On the first click nothing change and the usercontrol disappears on the second click..
0
SamJ
Top achievements
Rank 1
answered on 11 Feb 2009, 01:55 PM
Hi max,

From what you said I think that you should have missed something when loading your user controls dynamically. Can you check out this link and see if this is the issue?

Let me know how it goes.
0
max
Top achievements
Rank 1
answered on 11 Feb 2009, 02:03 PM

I forgot this piece of code..

    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
 
        If Not String.IsNullOrEmpty(Me.LatestLoadedControlName) Then 
            LoadUserControl(Me.LatestLoadedControlName)  
        End If 
 
    End Sub 

Now I'ts working..
Thanks
Tags
Ajax
Asked by
max
Top achievements
Rank 1
Answers by
SamJ
Top achievements
Rank 1
max
Top achievements
Rank 1
Share this question
or