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

[Solved] RadGrid EditFormTemplate not returning Text property of textbox

6 Answers 314 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Haines
Top achievements
Rank 1
John Haines asked on 01 Sep 2009, 04:24 PM
I am trying to use the CommandItem to add a new record to my grid. But when I process the "RadGrid2_ItemCommand" event in my code-behind, the textbox I entered a value into does not contain the text.

My procees is this: I click the "add new record" link and the insert template displays where I can type in my field data. I click insert and it goes to the Radgrid2_itemcommand event. But the Text property of the textbox is empty.

Thoughts?

Here is the radgrid (simplified)...

      <telerik:RadGrid ID="RadGrid2" runat="server" PageSize="20" AllowPaging="True" AllowSorting="True"
         GridLines="None" AllowFilteringByColumn="True" AutoGenerateColumns="false" OnItemDataBound="RadGrid2_ItemDataBound"
         OnItemCommand="RadGrid2_ItemCommand">
         <ClientSettings>
            <Selecting AllowRowSelect="True" />
         </ClientSettings>
         <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top">
            <Columns>
               <telerik:GridBoundColumn DataField="ProposalName" DataType="system.string" HeaderText="Proposal Id"
                  ReadOnly="True" SortExpression="ProposalName" UniqueName="ProposalName">
               </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
               <FormTemplate>
                  <table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
                     <tr>
                        <td>
                           Proposal Id:
                        </td>
                        <td>
                           <asp:TextBox ID="TextBoxInsertedProposalName" Text='<%# Bind( "ProposalName" ) %>'
                              runat="server" />
                        </td>
                     </tr>
                     <tr>
                        <td align="right" colspan="2">
                           <asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                              runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                           </asp:Button>&nbsp;
                           <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                           </asp:Button>
                        </td>
                     </tr>
                  </table>
               </FormTemplate>
            </EditFormSettings>
         </MasterTableView>
      </telerik:RadGrid>

Here is my code-behind...

    protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
    {

        if (e.CommandName == RadGrid.PerformInsertCommandName) // after the user clicks "insert"
        {
            GridEditableItem editedItem = e.Item.OwnerTableView.GetInsertItem();

            string insertedProposalName = (editedItem.FindControl("TextBoxInsertedProposalName") as TextBox).Text;
            // this should have the value ABCD but instead has the value string.empty

            Hashtable newValues = new Hashtable();
            foreach (DictionaryEntry entry in newValues)
            {
                string key = entry.Key.ToString();

                if (key == "ProposalName")
                {
                    string value = entry.Value.ToString();

                    Debug.Print(key + " = " + value);
                    break;
                }
            }
        }
    }

6 Answers, 1 is accepted

Sort by
0
Mr. Plinko
Top achievements
Rank 1
answered on 03 Sep 2009, 03:08 PM
So are you saying that the grid doesn't update with the value you enter into the textbox or are you saying that you can't get the ProposalName value in the code behind (although it is updating the grid)?
0
Martin
Telerik team
answered on 03 Sep 2009, 03:28 PM
Hello John,

I tried your code and it run as expected on my end. In your sample I added a new label control showing the text entered when the insert button is clicked.

If I miss something or you need further assistance please let us know.

Regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
John Haines
Top achievements
Rank 1
answered on 03 Sep 2009, 05:58 PM
When I use the same code that you are using I do not see any of the values from the webusercontrol form on postback. The textbox control exists on the form but it contains only the value it had when the form was populated and not the changed value from the user typing in the textbox.

Here's what my be different:

These are my files:

Proposal.aspx (contains radscriptmanager, radajaxmanager and a radsplitter)

MasterpartsList.ascx is a control inside proposal.aspx. It has a radcodeblock for the doubleclick, a radajadloadingpanel, a radajaxmanagerproxy and a radgrid. the Radgrid has an editformssettings with a usercontrolname of proposalpartdetails.ascx.

ProposalPartDetails.ascx had a <table> block with <telerik:RadTextBox id="TextBoxPartNumber"> controls in it.

The code behind for this file is the one that cannot see the value of the TextBoxPartNumber control.

The statement I am using to extract the value from the popup edit form is

string p = (this.FindControl("TextBoxPartNumber") as RadTextBox).Text;

which always returns an empty string.

Is it possible that something to do with my ajax settings is messing this up?

thanks again for your help.

- John
0
Charlie Crawford
Top achievements
Rank 1
answered on 04 Sep 2009, 02:26 AM
I had the exact same problem... see this post for details.

In the end, I was able to get the values by accessing the form's Post data:

 
Dim inputText As String = Request.Form(e.Item.FindControl("name_of_control").UniqueID)  

I still don't know why the documented methods don't work as expected, but I suspect it has something to do with a PostBack occuring from the hosting page that overwrites the new data. The other ways (documentation methods) work elsewhere in our application, but not on the Web User Controls.

Hope this helps,

Charlie
0
Akber Ali
Top achievements
Rank 1
answered on 30 Oct 2009, 01:29 AM
you are absolutely write. I tried every thing but on post back I am not getting the values that I entered. Off course the RadGrid is placed in a User Control and then User Control in .aspx.

The events are caught, but sorry to say that newly entered values are no where. I am still getting the same old values. This is such a big big bug.
0
Johny
Top achievements
Rank 1
answered on 03 Nov 2009, 11:57 AM
Hello Guys,

I found this help topic that might be useful in your case.

http://www.telerik.com/help/aspnet-ajax/grdupdatingvaluesusercontrolformtemplate.html

I hope this helps.
Johny
Tags
Grid
Asked by
John Haines
Top achievements
Rank 1
Answers by
Mr. Plinko
Top achievements
Rank 1
Martin
Telerik team
John Haines
Top achievements
Rank 1
Charlie Crawford
Top achievements
Rank 1
Akber Ali
Top achievements
Rank 1
Johny
Top achievements
Rank 1
Share this question
or