Get content of a textbox within an Item termplate

4 posts, 0 answers
  1. Clive Hoggar
    Clive Hoggar avatar
    334 posts
    Member since:
    Nov 2008

    Posted 23 Apr 2009 Link to this post

    Hi
    I have looked at the docs and found the example a bit obscure, and have searched the forum posts,
    and I am still struggling to come up with the right VB code to read the text box values.
    Here is how they are nested:
    <telerik:RadPanelBar ID="RadPanelBar1" Runat="server">  
      <Items> 
        <telerik:RadPanelItem runat="server" Text="ContactDetails">  
           <Items> 
              <telerik:RadPanelItem runat="server" Text="">  
                 <ItemTemplate> 
                    <telerik:RadTextBox ID="RadTextBoxEmail" Runat="server">  
                    </telerik:RadTextBox> 
     
                    (more text boxes) 
                </ItemTemplate>
              </telerik:RadPanelItem>
           </Items>   
        </telerik:RadPanelItem>
      (more RadPanelItems)
      </Items>
    </telerik:RadPanelBar) 
    So exactly how do I get the content of the TextBox into my code
    so that I can save it to a database etc.?

    Thanks for all your great support guys

    Clive
  2. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 23 Apr 2009 Link to this post

    Hi Clive,

    Please find below a sample code snippet that shows the needed approach.

    ASPX:
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
    </telerik:RadScriptManager> 
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server">  
    <Items> 
        <telerik:RadPanelItem runat="server" Text="ContactDetails">  
        <Items> 
            <telerik:RadPanelItem runat="server" Value="templateHolder">  
            <ItemTemplate> 
                <telerik:RadTextBox ID="RadTextBoxEmail" runat="server">  
                </telerik:RadTextBox> 
                (more text boxes)  
            </ItemTemplate> 
            </telerik:RadPanelItem> 
        </Items> 
        </telerik:RadPanelItem> 
    </Items> 
    </telerik:RadPanelBar> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 
    </form> 

    Code-behind:
    Imports Telerik.Web.UI  
     
    Partial Class Default2  
        Inherits System.Web.UI.Page  
     
        Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click  
            Dim txtbox As RadTextBox = DirectCast(RadPanelBar1.FindItemByValue("templateHolder").FindControl("RadTextBoxEmail"), RadTextBox)  
            Label1.Text = txtbox.Text  
        End Sub 
    End Class 
     


    Greetings,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ana
    Ana avatar
    12 posts
    Member since:
    Apr 2014

    Posted 28 Jun 2014 Link to this post

    Hi Paul,

    Your code snippet is not working when the content of the text box originally assigned a value by a data bind in page load event.

    Please check this scenario:

    1.  ASPX code is exactly what had given. No changes to it. You can use as is.

    2. Please use the following page load event code ( it is in C#). In this event code, I am originally assigning a content to the text box.

    protected void Page_Load(object sender, EventArgs e)
    {
    RadTextBox txtbox = (RadTextBox)(RadPanelBar1.FindItemByValue("templateHolder").FindControl("RadTextBoxEmail"));
    txtbox.Text = "Telerik";


    3. Now use the below code for the Button1 Click event.

    protected void Button1_Click(object sender, EventArgs e)
    {

    RadTextBox txtbox = (RadTextBox)(RadPanelBar1.FindItemByValue("templateHolder").FindControl("RadTextBoxEmail"));
    Label1.Text = txtbox.Text;
    }

    4. Run the debugger.  During the page load, the Textbox.Text you see as "Telerik".  Upto this part everything is fine.   Now change the text box content to something else and click on Submit button.  The modified content will be erased and displays the original Text which is "Telerik".

    So basically, the Label1.Text is always the Original assigned Text during the page load event.  It will never get changed no matter you change the content of it. 

    Can you please proive me the solution?

    Thank you.

  5. Ana
    Ana avatar
    12 posts
    Member since:
    Apr 2014

    Posted 29 Jun 2014 Link to this post

    At last I am able to resolve this issue. Hope it may helpful to others.

    I can retain the textbox content by making a small change in Page Load event. Since the text box content get lost after post back, I retained that content by adding !IsPost in page load event code.

    ​protected void Page_Load(object sender, EventArgs e)
    {
    If(!IsPostback)
    {
    RadTextBox txtbox = (RadTextBox)(RadPanelBar1.FindItemByValue("templateHolder").FindControl("RadTextBoxEmail"));
    txtbox.Text = "Telerik";
    }

Back to Top