Unable to see Value in usercontrol that is inside radpanelbar

2 posts, 0 answers
  1. Madhu Palakurthi
    Madhu Palakurthi avatar
    48 posts
    Member since:
    Nov 2009

    Posted 19 Dec 2012 Link to this post


    I have Default.aspx page like this ..

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <title>ASP.NET PanelBar Demo - Dynamic Creation</title>
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
        <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
            EnableRoundedCorners="false" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <telerik:AjaxSetting AjaxControlID="RadButton1">
                        <telerik:AjaxUpdatedControl ControlID="RadPanelBar1" LoadingPanelID="RadAjaxLoadingPanel1">
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
            <telerik:RadPanelBar runat="server" ID="RadPanelBar1" Height="200" ExpandMode="FullExpandedItem">
        <telerik:RadButton ID="RadButton1" runat="server"   Text="RadButton">

    Default.aspx.vb :

    Imports Telerik.Web.UI
    Partial Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
            End If
        End Sub
        Protected Sub RadButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadButton1.Click
            Dim i As Integer = 0
            If RadPanelBar1.Items.Count = 0 Then
                Do While (i < 5)
                    Dim dateItem As New RadPanelItem()
                    dateItem.Text = "Test" + i.ToString()
                    Dim control As New RadPanelItem()
                    Dim Panel1 As New Panel()
                    Session("testText") = " Label" + i.ToString()
                    Dim myControl As Control = LoadControl("TestUC.ascx")
                    i = i + 1
            End If
        End Sub
    End Class

    ASCX :

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TestUC.ascx.vb" Inherits="TestUC" %>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    ASCX.VB :

    Partial Class TestUC
        Inherits System.Web.UI.UserControl
        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        End Sub
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                Label1.Text = Session("testText")
            End If
        End Sub
    End Class

    When I am click on RadButton1 then I am adding 5 times usercontrol dynamically .If RadPanelBar1.Items.Count = 0 ..So I can able to see label value in 5 usercontrols that added in to radpanelbar.

    If I click on RadButton1 2nd time then nothing to do becuase 5 time usercontrol added already in to radpanelbar.. that's  why I put condition like this

    If RadPanelBar1.Items.Count = 0
    ' Add user control here..
    End If

    Above condition causes nothing loaded in to UI.

    Working Image here :  https://docs.google.com/open?id=0B2iTYXKyTlBpZU5ZY1J0SV9FaXc

    Not Working Image :  https://docs.google.com/open?id=0B2iTYXKyTlBpTmNGdXNQTjJCVGs

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Dec 2012 Link to this post


    This happens because dynamically created controls added to other dynamically created controls are lost after a postback. You need to recreate them on every page load. Please take a look into this documentation for more information about adding Templates at Runtime.

  3. Telerik UI for ASP.NET Core is out
Back to Top