This is a migrated thread and some comments may be shown as answers.
RadUpload in an Ajaxified Grid fires twice
4 Answers 66 Views
This is a migrated thread and some comments may be shown as answers.
michael
Top achievements
Rank 1
michael asked on 12 Aug 2008, 08:40 PM
Greetings.
I followed the example for Using RadUpload in an Ajaxified Grid, making only minor adjustments for my data connections and field name. 
RadGrid1_InsertCommand, and DeleteCommand both fire twice.  I've attached to the aspnet process in an attempt to troubleshoot and I'm getting no where. 

On Insert: a file gets copied to my directory and two records are created in my database.  Alternatively on Delete, the file gets purged and the first record gets deleted, then i get a stop error b/c on the second time around the file no longer exists. 

Any thoughts would be greatly appreciated.

4 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 13 Aug 2008, 05:28 AM
Hi Michael,

Could it be that the event handlers are attached twice? Please, check if you have the command event handlers of RadGrid declared to the control (in the ASPX/ASCX declaration) and if the methods also have the Handles keyword.

Kind regards,
Erjan Gavalji
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
michael
Top achievements
Rank 1
answered on 13 Aug 2008, 08:38 PM

Thanks for the response, Erjan.
I attached some of aspx, as well as the delete command. 
I believe these concur with your initial thoughts.
Any other suggestions?  Let me know if I should attach the complete files in a zip.

<body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0">
    <form id="form1" runat="server">
    <asp:scriptmanager id="ScriptManager1" runat="server">
        </asp:scriptmanager>
        <%--<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>--%>
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
             <script type="text/javascript">
                    //On insert and update buttons click temporarily disables ajax to perform upload actions
                    function conditionalPostback(e, sender)
                    {
                        var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                  if (sender.EventTarget.match(theRegexp))
                  {
                      var upload = $find(window['UploadId']);
                     
                      //AJAX is disabled only if file is selected for upload
                      if(upload.getFileInputs()[0].value != "")
                      {
                          sender.EnableAjax = false;
                      }
                  }
                    }    
                </script>     
   </telerik:RadScriptBlock>
    <%--<telerik:RadScriptManager ID="RadScriptManager1"
            Runat="server">
        </telerik:RadScriptManager>--%>
  <telerik:radajaxpanel id="RadAjaxPanel1" runat="server" clientevents-onrequeststart="conditionalPostback">
            <telerik:radprogressmanager id="RadProgressManager1" runat="server" />
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
                AllowSorting="True" AutoGenerateColumns="False" DataMember="EDMS"
                EnableAJAX="true" EnableAJAXLoadingTemplate="False" GridLines="None"
                Height="100%" LoadingTemplateTransparency="50"
                OnDeleteCommand="RadGrid1_DeleteCommand"
                OnInsertCommand="RadGrid1_InsertCommand"
                OnItemDataBound="RadGrid1_ItemDataBound"
                OnUpdateCommand="RadGrid1_UpdateCommand" PageSize="4" showstatusbar="true"
                Skin="Office2007" SkinsPath="~/Skins/Grid" style="height: 200px"
                Width="99%" >
                <PagerStyle Mode="NextPrevAndNumeric" />
                <%--<ClientSettings>
                <ClientEvents OnRequestStart="conditionalPostback" />
            </ClientSettings>--%>
                <MasterTableView CommandItemDisplay="Bottom" DataKeyNames="ID"
                    DataMember="EDMS" editmode="EditForms" Width="100%">
                    <CommandItemSettings AddNewRecordImageUrl="~/Skins/Grid/WinXP/AddRecord.gif"
                        RefreshImageUrl="~/Skins/Grid/WinXP/Refresh.gif" />
                    <EditFormSettings>
                        <EditColumn CancelImageUrl="~/Skins/Grid/WinXP/Cancel.gif"
                            EditImageUrl="~/Skins/Grid/WinXP/Edit.gif"
                            FilterImageUrl="~/Skins/Grid/WinXP/Filter.gif"
                            InsertImageUrl="~/Skins/Grid/WinXP/Insert.gif"
                            SortAscImageUrl="~/Skins/Grid/WinXP/SortAsc.gif"
                            SortDescImageUrl="~/Skins/Grid/WinXP/SortDesc.gif"
                            UniqueName="EditCommandColumn1" UpdateImageUrl="~/Skins/Grid/WinXP/Update.gif">
                        </EditColumn>
                    </EditFormSettings>
                    <Columns>
                        <telerik:GridEditCommandColumn CancelImageUrl="~/Skins/Grid/WinXP/Cancel.gif"
                            EditImageUrl="~/Skins/Grid/WinXP/Edit.gif"
                            FilterImageUrl="~/Skins/Grid/WinXP/Filter.gif"
                            InsertImageUrl="~/Skins/Grid/WinXP/Insert.gif"
                            SortAscImageUrl="~/Skins/Grid/WinXP/SortAsc.gif"
                            SortDescImageUrl="~/Skins/Grid/WinXP/SortDesc.gif"
                            UpdateImageUrl="~/Skins/Grid/WinXP/Update.gif">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridTemplateColumn FilterImageUrl="~/Skins/Grid/WinXP/Filter.gif"
                            HeaderText="File Name" ItemStyle-Wrap="false"
                            SortAscImageUrl="~/Skins/Grid/WinXP/SortAsc.gif"
                            SortDescImageUrl="~/Skins/Grid/WinXP/SortDesc.gif" SortExpression="FilePath"
                            UniqueName="FilePath" >
                            <ItemTemplate>
                                <asp:Label ID="lblName" runat="server"
                                    Text='<%# DataBinder.Eval(Container.DataItem, "FilePath") %>' Width="35%"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Wrap="False" />
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="Description"
                            FilterImageUrl="~/Skins/Grid/WinXP/Filter.gif" HeaderText="Description"
                            SortAscImageUrl="~/Skins/Grid/WinXP/SortAsc.gif"
                            SortDescImageUrl="~/Skins/Grid/WinXP/SortDesc.gif" UniqueName="Description">
                            <ItemTemplate>
                                <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txbDescription" runat="server"
                                    Style="width: 205px; margin-left: 4px;" Text='<%# Bind("Description") %>'
                                    TextMode="MultiLine"></asp:TextBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn FilterImageUrl="~/Skins/Grid/WinXP/Filter.gif"
                            HeaderText="File Link" SortAscImageUrl="~/Skins/Grid/WinXP/SortAsc.gif"
                            SortDescImageUrl="~/Skins/Grid/WinXP/SortDesc.gif" UniqueName="Upload">
                            <ItemTemplate>
                                <a href='<%# "../edms/" & DataBinder.Eval(Container.DataItem, "LayerName") & "/" & DataBinder.Eval(Container.DataItem, "FilePath") %>'
                                    target="_blank">
                                <asp:Image ID="ImageThumbnail" runat="server"
                                    AlternateText="Click here to open or download the file!"
                                    ImageUrl='<%# "../images/icons/" & Right(DataBinder.Eval(Container.DataItem, "FilePath"), 3) & ".gif" %>'
                                    Style="border-width: 0px;" />
                                </a>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadUpload ID="RadUpload1" runat="server"
                                    AllowedFileExtensions=".doc,.pdf,.jpg,.bmp,.gif,.dib,.jpeg,.jpe,.jfif,.png,.tif,.tiff,.txt,.text,.doc,.docx,.xls,.xlsx"
                                    ControlObjectsVisibility="None" InitialFileInputsCount="1"
                                    MaxFileInputsCount="1" MaxFileSize="1000000" />
                                <%--<asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="RadUpload1"
                                Display="Dynamic" ErrorMessage="Please, select a file!" SetFocusOnError="true">
                                </asp:RequiredFieldValidator>--%>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridButtonColumn CommandName="Delete"
                            FilterImageUrl="~/Skins/Grid/WinXP/Filter.gif" HeaderText="Delete"
                            SortAscImageUrl="~/Skins/Grid/WinXP/SortAsc.gif"
                            SortDescImageUrl="~/Skins/Grid/WinXP/SortDesc.gif" Text="Delete"
                            UniqueName="column">
                        </telerik:GridButtonColumn>
                    </Columns>
                    <ExpandCollapseColumn CollapseImageUrl="~/Skins/Grid/Telerik/SingleMinus.gif"
                        ExpandImageUrl="~/Skins/Grid/Telerik/SinglePlus.gif"
                        FilterImageUrl="~/Skins/Grid/Telerik/Filter.gif"
                        SortAscImageUrl="~/Skins/Grid/Telerik/SortAsc.gif"
                        SortDescImageUrl="~/Skins/Grid/Telerik/SortDesc.gif" Visible="False">
                        <HeaderStyle Width="19px" />
                    </ExpandCollapseColumn>
                    <RowIndicatorColumn FilterImageUrl="~/Skins/Grid/Telerik/Filter.gif"
                        SortAscImageUrl="~/Skins/Grid/Telerik/SortAsc.gif"
                        SortDescImageUrl="~/Skins/Grid/Telerik/SortDesc.gif" Visible="False">
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                </MasterTableView>
                <FilterMenu NotSelectedImageUrl="~/Skins/Grid/WinXP/NotSelectedMenu.gif"
                    SelectedImageUrl="~/Skins/Grid/WinXP/SelectedMenu.gif">
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </FilterMenu>
            </telerik:RadGrid>
        </telerik:radajaxpanel>&nbsp;
   
  
    </form>
    </body>
</html>

-----------------------------

Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.DeleteCommand
        Dim id As Integer = CInt(RadGrid1.MasterTableView.DataKeyValues(e.Item.ItemIndex)("ID"))
        DeleteFileAndThumbnail(id)
        sqlDataFunctions.deleteDocuments(id)
    End Sub

 

0
Erjan Gavalji
Telerik team
answered on 14 Aug 2008, 07:54 AM
Hi Michael,

Indeed, this is exactly the case - the declaration of the RadGrid has

OnDeleteCommand="RadGrid1_DeleteCommand"
OnInsertCommand="RadGrid1_InsertCommand"


declaration and the

Protected Sub RadGrid1_DeleteCommand

has the

Handles RadGrid1.DeleteCommand statement.

Please, remove either the Handles statements, or the OnDeleteCommand/OnInsertCommand inline declarations.

Kind regards,
Erjan Gavalji
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
michael
Top achievements
Rank 1
answered on 14 Aug 2008, 02:24 PM
Thanks Erjan;
I removed the Handles statements and it runs correctly.
Thank you for your support!
Asked by
michael
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
michael
Top achievements
Rank 1
Share this question
or