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

RadGrid Edit Template - InsertItemTemplate problem

2 Answers 201 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 18 Mar 2014, 04:19 PM
Hi to all,
I'm facing an annoying problem with RadGrid OnInsertCommand + RadEditor, more specifically (following this demo on Telerik examples portal: http://demos.telerik.com/aspnet-ajax/editor/examples/edittemplate/defaultcs.aspx) I'm trying to handle the insert command from code behind and the problem is that I'm not able to get the 'Content' of the RadEditor after the Insert calls the code behind.

Some code will be more explicative:

.aspx (my RadGrid with RadEditor inside)
<telerik:RadGrid ID="Content_RadGrid" runat="server"
    AutoGenerateColumns="false"
    AutoGenerateInsertColumn="true"
    AutoGenerateEditColumn="true"
    AutoGenerateDeleteColumn="true"
    OnInsertCommand="Content_RadGrid_InsertCommand"
    OnUpdateCommand="Content_RadGrid_UpdateCommand">
    <MasterTableView DataKeyNames="pID" CommandItemDisplay="Bottom">
        <Columns>
            <telerik:GridTemplateColumn UniqueName="ID" Display="true">
                    <ItemTemplate>
                        <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("pID") %>'></asp:Label>
                    </ItemTemplate>
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn UniqueName="Content" ItemStyle-HorizontalAlign="Justify">
                    <ItemTemplate>
                        <asp:Label ID="lblField1" CssClass="text" runat="server" Text='<%# Eval("Content") %>'></asp:Label>
                    </ItemTemplate>
 
                    <InsertItemTemplate>
                        <telerik:RadEditor ID="Insert_RadEditor" runat="server" Content='<%# Bind("Content") %>' Language="it-IT" EnableResize="false" Width="1000px" Height="300px">
                            <Tools>
                                <telerik:EditorToolGroup>
                                        <telerik:EditorTool Name="Cut"></telerik:EditorTool>
                                        <telerik:EditorTool Name="Copy"></telerik:EditorTool>
                                        <telerik:EditorTool Name="Paste"></telerik:EditorTool>
                                </telerik:EditorToolGroup>
                            </Tools>
                        </telerik:RadEditor>
                    </InsertItemTemplate>
 
                    <EditItemTemplate>
                        <telerik:RadEditor ID="Update_RadEditor" runat="server" Content='<%# Bind("Content") %>' Language="it-IT" EnableResize="false" Width="1000px" Height="300px">
                            <Tools>
                                <telerik:EditorToolGroup>
                                        <telerik:EditorTool Name="Cut"></telerik:EditorTool>
                                        <telerik:EditorTool Name="Copy"></telerik:EditorTool>
                                        <telerik:EditorTool Name="Paste"></telerik:EditorTool>
                                </telerik:EditorToolGroup>
                            </Tools>
                        </telerik:RadEditor>
                    </EditItemTemplate>
 
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

.aspx.cs
#region Test Methods
 
    protected void Content_RadGrid_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        RadEditor rd = e.Item.FindControl("Insert_RadEditor") as RadEditor;
 
        string content = rd.Content;
        string text = rd.Text;
 
        Response.Write("Breakpoint1");
    }
 
    protected void Content_RadGrid_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        RadEditor rd = e.Item.FindControl("Update_RadEditor") as RadEditor;
 
        string content = rd.Content;
        string text = rd.Text;
 
        Response.Write("Breakpoint2");
    }

The problem is that when i hit the Insert and the debugger make me jump at 'Breakpoint1' my Content and Text are empty ("") instead of what I wrote before.  When I hit Update in Edit mode (obviously debugger jump on 'Breakpoint2') Content and Text have the right values from the DataSource.

I'm sure that I get the right RadEditor Control both in Insert that in Update because if I change the properties of one of that I can use the debugger to obtain evidence that I'm taking the right control.

I'm saying that is a strange issue because if you try providing Datasource directly in the .aspx, like in the Telerik Demo, all works perfectly.
I have tried many approaches found on the internet and in many forums but no one fits with my problem and I can't find a working example of handling the Insert command.
Am I missing something?

Thanks in advance
M

2 Answers, 1 is accepted

Sort by
0
Marco
Top achievements
Rank 1
answered on 19 Mar 2014, 10:55 AM
Hi to all again,
I've done one step closer to the truth I think, searching with the right searching string I've found that many people have had the same problem in get the updated value of a rad editor in a variety of different situations.
In effect I can say that even in the update command I'm only able to get the original value from the Radeditor and not the updated value, same problem I'm facing in Insert command.
All brings to this post: http://www.telerik.com/support/kb/aspnet-ajax/editor/details/radeditor-content-not-saved-after-ajax-update-in-ie9-firefox-google-chrome-and-safari

We have a description of the issue and a couple of possible solutions but I'm not able to figure out how I can stick one of this to my particular situation, the problem is that I'm using built-in commands that does not accept UseSubmitBehavior="false" or any other solution.
Another problem is, if I build the command columns from scratch, how can I handle the open of the RadEditor while I'm editing or inserting the row?

I apologize for my 'rookie' skills on this argument.
Regards
0
Marco
Top achievements
Rank 1
answered on 19 Mar 2014, 01:46 PM
Solved,
for quit the question my error is that I've implemented the Datasource providing code in the PageLoad instead of using the correct binding behaviour of 'OnNeedDataSource'.
This forces the RadEditor to reset to default all the values at every postback or, in case we use the '!this.IsPostBack' the table results empty.
Finally It was my fault.

I hope this can help someone else
Tags
Editor
Asked by
Marco
Top achievements
Rank 1
Answers by
Marco
Top achievements
Rank 1
Share this question
or