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:
ASPX VB
ASCX
ASCX VB
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 Object, ByVal e As System.EventArgs) Handles Button1.Click |
Label1.Text = DateTime.Now.ToString() |
End Sub |
Private Sub Button2_Click(ByVal sender As Object, ByVal 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 Nothing) Then |
Dim previousControl As Control = Panel1.FindControl(LatestLoadedControlName.Split("."c)(0)) |
If Not (previousControl Is Nothing) Then |
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 Object, ByVal e As System.EventArgs) Handles Button1.Click |
Label1.Text = DateTime.Now.ToString() |
End Sub |