RadGrid - after postback textbox field is empty in the code behind

2 posts, 0 answers
  1. Walt
    Walt avatar
    1 posts
    Member since:
    Feb 2014

    Posted 06 Jun Link to this post

    Hi,

    I am using a RadGrid to show data (obviously).  Within a specific cell I have a literal that is called "DocumentName".  The user has an option to rename that generic name to something custom.  What I do is have a button that they click and an asp:TextBox control becomes visible with a save button.  When I enter text into that textbox and hit the save button I want to get that new value from the textbox.  However, I am getting an empty string every time. I have tried multiple ways  Here is my code.

    foreach (GridDataItem g in EventsDocsRadGV.Items)
    {

    // First way - returns an empty string
    TextBox RenameDocumentName = (TextBox)g.FindControl("RenameDocumentName");

    // Second way - returns an empty string
    string txt = (g["EventTypeDesc"].FindControl("RenameDocumentName") as TextBox).Text;

    // Third way - returns an empty string
    GridDataItem item = (GridDataItem)g;
    TextBox RenameDocumentName2 = (TextBox)item["EventTypeDesc"].FindControl("RenameDocumentName");

    }

    I also tried the same only wrapped in this loop
    foreach (GridDataItem g in EventsDocsRadGV.MasterTableView.Items)
    {

    // First way - returns an empty string
    TextBox RenameDocumentName = (TextBox)g.FindControl("RenameDocumentName");

    // Second way - returns an empty string
    string txt = (g["EventTypeDesc"].FindControl("RenameDocumentName") as TextBox).Text;
    // Third way - returns an empty string
    GridDataItem item = (GridDataItem)g;
    TextBox RenameDocumentName2 = (TextBox)item["EventTypeDesc"].FindControl("RenameDocumentName");

    }

    I can access the other properties and cells that were bound onitemdatabound but not this textbox.  Ideas?

    Thanks!

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 08 Jun Link to this post

    Hi Walt,

    Please examine the article below that illustrates how to access the controls inside grid cells in various scenarios.


    With that said, would you elaborate in more detail on what is your exact scenario? Where are the Button, Literal and TextBox controls placed? Are they inside the grid or outside? What event are you using to access the controls and change the text for the Literal?

    Also, why do you need to implement that behavior? Having better understanding of your goal will enable us to provide more to-the-point suggestions on how to implement it.

    Regards,
    Viktor Tachev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top