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

Insert/edit mode and exceptions

3 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alessandra C
Top achievements
Rank 1
Alessandra C asked on 15 Mar 2010, 02:23 PM
I have a radgrid populated by the "OnNeedDataSource" event.
Radgrid has edits form template to update and insert records that call the "OnItemCommand" event.
This works fine while no exception is raised in update or insert methods but in the other case I have the following problem:
my code keeps the radgrid open in edit/insert mode and keeps also the new values inserted from the user but the commandbuttons don't call the ItemCommand anymore, at this point, clicking on the confirm button, it seems that it make just a simple postback erasing all the data in the textboxes.
Here it is an example of my code

 

HTML  
<telerik:RadGrid ID="grid_utenti" runat="server" AllowAutomaticInserts="false"   
AllowAutomaticUpdates="false"   
OnNeedDataSource="grid_utenti_NeedDataSource"   
OnItemCommand="grid_utenti_ItemCommand">  
 
CS  
 
protected void grid_utenti_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
             grid_utenti.DataSource = call to a method that returns a dataset;            
        }  
         
        protected void grid_utenti_ItemCommand(object sender, GridCommandEventArgs e)  
        {                         
            if (e.CommandName == RadGrid.PerformInsertCommandName || e.CommandName == RadGrid.UpdateCommandName)  
            {  
try  
{  
               //call to method that insert/update  
                 
               }  
catch(Exception exc)  
{                      
                    e.Canceled = true;  
 
        }
}

Thank you
Alessandra

 

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 16 Mar 2010, 02:16 PM
Hello Alessandra,

The provided information is not enough to locate the cause for the problem. Could you paste your whole mark-up and code-behind? Which buttons do you mean by the command buttons that do not fire the ItemCommand - perhaps, the Update/Insert/Cancel buttons? Could you also specify which one the "confirm" button is.

Thanks in advance.

Regards,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Alessandra C
Top achievements
Rank 1
answered on 16 Mar 2010, 02:49 PM
Once the insert or update fails the e.Canceled is valued to True and even if the user corrects the wrong fields and
clicks to save the changes, the event doesn't fire anymore.

Here is the code behind:

 

protected void grid_utenti_ItemCommand(object sender, GridCommandEventArgs e)  
        {  
 
            if ((e.CommandName == RadGrid.EditCommandName) || (e.CommandName == RadGrid.InitInsertCommandName))  
                e.Item.OwnerTableView.AllowFilteringByColumn = false;  
            else 
                e.Item.OwnerTableView.AllowFilteringByColumn = true;  
              
            if (e.CommandName == RadGrid.PerformInsertCommandName || e.CommandName == RadGrid.UpdateCommandName)  
            {  
                GridEditableItem item = (GridEditableItem)e.Item;  
                int iId = -1;  
                if (e.CommandName == RadGrid.UpdateCommandName)  
                    iId = System.Convert.ToInt32(item.GetDataKeyValue("id"));  
 
                // ------------------------------- this is a call to a stored procedure ...  
                DataManager.InsOrUpdUtente(iId, ((RadTextBox)item.FindControl("txt_userna")).Text, ((RadTextBox)item.FindControl("txt_passwd")).Text,  
                ((RadTextBox)item.FindControl("txt_domandapasswd")).Text, ((RadTextBox)item.FindControl("txt_rispostapasswd")).Text,  
                 ((RadioButtonList)item.FindControl("radio_corso")).SelectedValue, ((RadTextBox)item.FindControl("txt_email")).Text,  
                ((RadTextBox)item.FindControl("txt_nome")).Text, ((RadTextBox)item.FindControl("txt_cognome")).Text,  
                ((RadTextBox)item.FindControl("txt_azienda")).Text, ((RadioButtonList)item.FindControl("radio_ecostampa")).SelectedValue, ((RadTextBox)item.FindControl("txt_telefono")).Text);  
 
                //... sp returns less than 0 if fails  
                if (DataManager.Rescod < 0)  
                {  
                    lbl_messaggio.Text = DataManager.Resdesc; //... and the reason for faailure                     
                    e.Canceled = true;  
                }  
                else 
                    lbl_messaggio.Text = "";  
            }  
        } 

Here is the markup

 <telerik:RadGrid ID="grid_utenti" runat="server" AllowFilteringByColumn="false"   
                ShowFooter="True" PageSize="20" 
                AllowPaging="True" AllowSorting="True" GridLines="None" ShowStatusBar="True"    
                AllowAutomaticInserts="false"   
                AllowAutomaticUpdates="false"                
                OnNeedDataSource="grid_utenti_NeedDataSource"   
                OnItemDataBound="grid_utenti_ItemDataBound" 
                OnItemCommand="grid_utenti_ItemCommand">  
                <MasterTableView AutoGenerateColumns="false" AllowFilteringByColumn="true" CommandItemDisplay="Top" DataKeyNames="id,corso,ecostampa">                  
                    <Columns> 
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">  
                            <ItemStyle CssClass="MyImageButton" /> 
                        </telerik:GridEditCommandColumn> 
                        <telerik:GridTemplateColumn HeaderText="Agenzie" UniqueName="TemplateColumn" AllowFiltering="false" Reorderable="false">  
                             <ItemTemplate> 
                                 <href="#" onclick="openRad('<%# Eval("id") %>')">Agenzie</a> 
                             </ItemTemplate> 
                         </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn DataField="cognome" HeaderText="Cognome" SortExpression="cognome" EditFormColumnIndex="0">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_cognome" Text='<%# Eval("cognome") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_cognome" Width="200px" Text='<%# Bind("cognome") %>' MaxLength="50"></telerik:RadTextBox> 
                                <span style="color: Red"><asp:RequiredFieldValidator ID="Req_cognome" ControlToValidate="txt_cognome" ErrorMessage="*" runat="server"></asp:RequiredFieldValidator></span>  
                            </EditItemTemplate>                              
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn DataField="nome" HeaderText="Nome" SortExpression="nome" EditFormColumnIndex="0">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_nome" Text='<%# Eval("nome") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_nome" Width="200px" Text='<%# Bind("nome") %>' MaxLength="35"></telerik:RadTextBox> 
                                <span style="color: Red"><asp:RequiredFieldValidator ID="Req_nome" ControlToValidate="txt_nome" ErrorMessage="*" runat="server"></asp:RequiredFieldValidator></span>  
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>                                              
                        <telerik:GridTemplateColumn DataField="email" HeaderText="Email" SortExpression="email" EditFormColumnIndex="0">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_email" Text='<%# Eval("email") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_email" Width="200px" Text='<%# Bind("email") %>' MaxLength="50"></telerik:RadTextBox> 
                                <span style="color: Red"><asp:RequiredFieldValidator ID="Req_email" ControlToValidate="txt_email" ErrorMessage="*" runat="server"></asp:RequiredFieldValidator> 
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"   
                                    ErrorMessage="email non valida" ControlToValidate="txt_email" 
                                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> 
                                </span> 
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn DataField="userna" HeaderText="Username" SortExpression="userna" EditFormColumnIndex="1">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_userna" Text='<%# Eval("userna") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_userna" Width="200px" Text='<%# Bind("userna") %>' MaxLength="20"></telerik:RadTextBox> 
                                <span style="color: Red"><asp:RequiredFieldValidator ID="Req_userna" ControlToValidate="txt_userna" ErrorMessage="*" runat="server"></asp:RequiredFieldValidator></span>  
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>                          
                        <telerik:GridTemplateColumn DataField="passwd" HeaderText="Password" SortExpression="passwd" EditFormColumnIndex="1">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_passwd" Text='<%# Eval("passwd") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_passwd" Width="200px" Text='<%# Bind("passwd") %>' MaxLength="20"></telerik:RadTextBox> 
                                <span style="color: Red"><asp:RequiredFieldValidator ID="Req_passwd" ControlToValidate="txt_passwd" ErrorMessage="*" runat="server"></asp:RequiredFieldValidator></span>  
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>                                               
                        <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Domanda segreta" SortExpression="domandapasswd" EditFormColumnIndex="1">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_domandapasswd" Text='<%# Eval("domandapasswd") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_domandapasswd" Columns="32" Rows="3" TextMode="MultiLine" Text='<%# Bind("domandapasswd") %>'></telerik:RadTextBox>                                  
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>                                              
                        <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Risposta" SortExpression="rispostapasswd" EditFormColumnIndex="1">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_rispostapasswd" Text='<%# Eval("rispostapasswd") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_rispostapasswd" Columns="32" Rows="3" TextMode="MultiLine" Text='<%# Bind("rispostapasswd") %>'></telerik:RadTextBox>                                  
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>        
                        <telerik:GridTemplateColumn DataField="azienda" HeaderText="Azienda" SortExpression="azienda" EditFormColumnIndex="2">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_azienda" Text='<%# Eval("azienda") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><telerik:RadTextBox runat="server" ID="txt_azienda" Width="200px" Text='<%# Bind("azienda") %>' MaxLength="100"></telerik:RadTextBox> 
                                <span style="color: Red"><asp:RequiredFieldValidator ID="Req_azienda" ControlToValidate="txt_azienda" ErrorMessage="*" runat="server"></asp:RequiredFieldValidator></span>  
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>                           
                        <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Telefono" SortExpression="telefono" EditFormColumnIndex="2">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_telefono" Text='<%# Eval("telefono") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                               <telerik:RadTextBox runat="server" ID="txt_telefono" Width="200px" Text='<%# Bind("telefono") %>' MaxLength="20"></telerik:RadTextBox>                                  
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>                                                    
                        <telerik:GridTemplateColumn DataField="corso" HeaderText="Attivo" SortExpression="corso" EditFormColumnIndex="2">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_corso" Text='<%# Eval("corso") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><asp:RadioButtonList RepeatDirection="Horizontal" ID="radio_corso" runat="server"><asp:ListItem Text="Si" Value="S" Selected="True"/><asp:ListItem Value="N" Text="No" Selected="True"/></asp:RadioButtonList> 
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>                                                                         
                        <telerik:GridTemplateColumn DataField="ecostampa" HeaderText="Ecostampa" SortExpression="ecostampa" EditFormColumnIndex="2">  
                            <ItemTemplate> 
                                <asp:Label runat="server" ID="lbl_ecostampa" Text='<%# Eval("ecostampa") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <span><asp:RadioButtonList ID="radio_ecostampa" RepeatDirection="Horizontal" runat="server"><asp:ListItem Text="Si" Value="S"/><asp:ListItem Value="N" Text="No" Selected="True"/></asp:RadioButtonList> 
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn>    
                    </Columns> 
                 <EditFormSettings ColumnNumber="3" CaptionDataField="userna" CaptionFormatString="Modifica l'utente {0}">  
                   <FormTableItemStyle Wrap="False" VerticalAlign="top"></FormTableItemStyle> 
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> 
                    <FormMainTableStyle GridLines="None" CellSpacing="5" CellPadding="0" BackColor="#f0f0f0" 
                        Width="100%" /> 
                    <FormTableStyle CellSpacing="0" CellPadding="0" Height="155px" BackColor="#f0f0f0" /> 
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> 
                    <EditColumn ButtonType="ImageButton" InsertText="Inserisci nuovo utente" UpdateText="Aggiorna utente" 
                        UniqueName="EditCommandColumn1" CancelText="Annulla modifiche">  
                    </EditColumn> 
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle> 
                </EditFormSettings> 
                </MasterTableView> 
                <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">  
                </ClientSettings> 
            </telerik:RadGrid> 

thank you
0
Tsvetoslav
Telerik team
answered on 18 Mar 2010, 10:28 AM
Hello Alessandra,

Thanks for the code, however, I could not spot any problems with that. As I suspect that the issue lies elsewhere (perhaps with the ajax settings for the controls, if any), I'd ask you to open up a formal support ticket and send us a runnable test project that can be debugged on our side. This will also guarantee you a faster response time of a 24h time span.

All the best,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Alessandra C
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Alessandra C
Top achievements
Rank 1
Share this question
or