Inserting via formview not updating listview via ajax

2 posts, 0 answers
  1. DanInMa
    DanInMa avatar
    7 posts
    Member since:
    Aug 2013

    Posted 02 Oct 2013 Link to this post

    I know this has been discusses may times over. The majority of posts never quite apply or do nto have a definitive answer that I could get to work for me.

    I am using radajaxmanager, I have a hidden formview and a radlisteview. I an trying to use the formview to insert records ( also edit in the future if I can get this to work) , then hide the formview and refresh/rebind the listview without a page refresh.  I have tried about 100 times now and I cannot get the listview to refresh. 
    2 other issues. I couldnt get the default insert form for the radlistview to show, no matter what options I chose.
    When I delete a record from the list view, the add new button no longer works as well. I am guessing this is bad placement of the radcodeblock?


    <div class="section">
           <script type="text/javascript">
               function setCustomPosition(sender, args) {
                   sender.moveTo(sender.get_left(), sender.get_top());
               }
           </script>
       <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" onajaxrequest="RadAjaxManager1_AjaxRequest" >
           <AjaxSettings>
               <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="RadListView1" UpdatePanelCssClass="" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
           </AjaxSettings>
       </telerik:RadAjaxManager>
           <telerik:RadWindow ID="FVPopup" runat="server" Width="500px" Height="200px" Modal="true" OnClientShow="setCustomPosition" Top="20" Left="50">
               <ContentTemplate>
       
                       <asp:FormView CssClass="securityFormView" ID="FormView1" runat="server" DefaultMode="Insert" DataKeyNames="msgID" DataSourceID="SqlDataSource2">
                           <EditItemTemplate>
                               Title:
                               <asp:TextBox ID="titleTextBox" runat="server" Text='<%# Bind("title") %>' />
                               <br />
                               Message:
                               <asp:TextBox ID="messageTextBox" runat="server" Text='<%# Bind("message") %>' />
                               <br />
                               hasBeenBroadcast:
                               <asp:CheckBox ID="hasBeenBroadcastCheckBox" runat="server" Checked='<%# Bind("hasBeenBroadcast") %>' />
                               <br />
                               createdDate:
                               <asp:Label ID="createdDateLabel" runat="server" Text='<%# Bind("createdDate") %>' />
                               <br />
                               <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                                <asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                           </EditItemTemplate>
                           <InsertItemTemplate>
                               Title:        
                               <asp:TextBox ID="titleTextBox" runat="server" Text='<%# Bind("title") %>' />
                               <br />
                               Message:
                               <asp:TextBox ID="messageTextBox" runat="server" Text='<%# Bind("message") %>' />
                               <br />
                               <telerik:RadButton OnClientClicked="closePopupModality" ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" CausesValidation="true" />
                                <telerik:RadButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                           </InsertItemTemplate>
                           <ItemTemplate>
                               title:
                               <asp:Label ID="titleLabel" runat="server" Text='<%# Bind("title") %>' />
                               <br />
                               message:
                               <asp:Label ID="messageLabel" runat="server" Text='<%# Bind("message") %>' />
                               <br />
                               hasBeenBroadcast:
                               <asp:CheckBox ID="hasBeenBroadcastCheckBox" runat="server" Checked='<%# Bind("hasBeenBroadcast") %>' Enabled="false" />
                               <br />
                               createdDate:
                               <asp:Label ID="createdDateLabel" runat="server" Text='<%# Bind("createdDate") %>' />
                               <br />
                               msgID:
                               <asp:Label ID="msgIDLabel" runat="server" Text='<%# Eval("msgID") %>' />
                               <br />
                               <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
                                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
                                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
                           </ItemTemplate>
                       </asp:FormView>
     
     
               </ContentTemplate>
           </telerik:RadWindow>
                               <telerik:RadCodeBlock runat="server" ID="rdbScripts">
                           <script type="text/javascript">
                               function togglePopupModality() {
                                   var wnd = $find("<%=FVPopup.ClientID %>");
                                   wnd.set_modal(!wnd.get_modal());
                                   if (!wnd.get_modal()) document.documentElement.focus();
                               }
                               function closePopupModality() {
     
                                   var wnd = $find("<%=FVPopup.ClientID %>");
                                   wnd.close();
                                 var ajaxMan= $find("<%=RadAjaxManager1.ClientID %>")
                                 ajaxMan.ajaxRequest("Rebind");
                               }
                           </script>
                       </telerik:RadCodeBlock>
           <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" Skin="Office2010Blue" />
           <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NSMCWebConnectionString %>" DeleteCommand="DELETE FROM [ISAdminSecurity] WHERE [msgID] = @msgID" InsertCommand="INSERT INTO [ISAdminSecurity] ([title], [message], [hasBeenBroadcast], [createdDate]) VALUES (@title, @message, @hasBeenBroadcast, GETDATE())" SelectCommand="SELECT [title], [message], [hasBeenBroadcast], [createdDate], [msgID] FROM [ISAdminSecurity] ORDER BY [createdDate]" UpdateCommand="UPDATE [ISAdminSecurity] SET [title] = @title, [message] = @message, [hasBeenBroadcast] = @hasBeenBroadcast, [createdDate] = @createdDate WHERE [msgID] = @msgID">
               <DeleteParameters>
                   <asp:Parameter Name="msgID" Type="Int32" />
               </DeleteParameters>
               <InsertParameters>
                   <asp:Parameter Name="title" Type="String" />
                   <asp:Parameter Name="message" Type="String" />
                   <asp:Parameter Name="hasBeenBroadcast" Type="Boolean" DefaultValue="False" />
                   <asp:Parameter Name="createdDate" Type="DateTime" />
               </InsertParameters>
               <UpdateParameters>
                   <asp:Parameter Name="title" Type="String" />
                   <asp:Parameter Name="message" Type="String" />
                   <asp:Parameter Name="hasBeenBroadcast" Type="Boolean" />
                   <asp:Parameter Name="createdDate" Type="DateTime" />
                   <asp:Parameter Name="msgID" Type="Int32" />
               </UpdateParameters>
           </asp:SqlDataSource>
     
               <telerik:RadListView ID="RadListView1" runat="server" AllowPaging="True" DataKeyNames="msgID" DataSourceID="SqlDataSource1" AllowNaturalSort="True" InsertItemPosition="FirstItem" Skin="Office2010Blue">
                   <LayoutTemplate>
                       <div class="RadListView RadListView_Office2010Blue">
                           <table cellspacing="0" style="width: 100%;">
                               <thead>
                                   <tr class="rlvHeader">
                                       <th>
                                           <telerik:RadButton AutoPostBack="false" OnClientClicked="togglePopupModality" ID="AddNewItem" runat="server" Text="Add New" />
                                       </th>
                                       <th>
                                           title
                                       </th>
                                       <th>
                                           message
                                       </th>
                                       <th>
                                           hasBeenBroadcast
                                       </th>
                                       <th>
                                           createdDate
                                       </th>
                                       <th>
                                           msgID
                                       </th>
                                   </tr>
                               </thead>
                               <tfoot>
                                   <tr>
                                       <td colspan="6">
                                           <telerik:RadDataPager ID="RadDataPager1" runat="server" SEOPagingQueryPageKey="" Skin="Office2010Blue">
                                               <Fields>
                                                   <telerik:RadDataPagerButtonField FieldType="FirstPrev" LastButtonImageUrl="" NextButtonImageUrl="" PrevButtonImageUrl="" />
                                                   <telerik:RadDataPagerButtonField FieldType="NextLast" LastButtonImageUrl="" NextButtonImageUrl="" PrevButtonImageUrl="" />
                                               </Fields>
                                           </telerik:RadDataPager>
                                       </td>
                                   </tr>
                               </tfoot>
                               <tbody>
                                   <tr id="itemPlaceholder" runat="server">
                                   </tr>
                               </tbody>
                           </table>
                           <div style="display: none">
                               <telerik:RadCalendar ID="rlvSharedCalendar" runat="server" RangeMinDate="<%#new DateTime(1900, 1, 1) %>" Skin="<%#Container.Skin %>" />
                           </div>
                           <div style="display: none">
                               <telerik:RadTimeView ID="rlvSharedTimeView" runat="server" Skin="<%# Container.Skin %>" />
                           </div>
                       </div>
                   </LayoutTemplate>
                   <ItemTemplate>
                       <tr class="rlvI">
                           <td>
                               <asp:Button ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" CssClass="rlvBDel" Text=" " ToolTip="Delete" />
                               <asp:Button ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" CssClass="rlvBEdit" Text=" " ToolTip="Edit" />
                           </td>
                           <td>
                               <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
                           </td>
                           <td>
                               <asp:Label ID="messageLabel" runat="server" Text='<%# Eval("message") %>' />
                           </td>
                           <td>
                               <asp:CheckBox ID="hasBeenBroadcastCheckBox" runat="server" Checked='<%# Eval("hasBeenBroadcast") %>' Enabled="false" />
                           </td>
                           <td>
                               <asp:Label ID="createdDateLabel" runat="server" Text='<%# Eval("createdDate") %>' />
                           </td>
                           <td>
                               <asp:Label ID="msgIDLabel" runat="server" Text='<%# Eval("msgID") %>' />
                           </td>
                       </tr>
                   </ItemTemplate>
                   <AlternatingItemTemplate>
                       <tr class="rlvA">
                           <td>
                               <asp:Button ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" CssClass="rlvBDel" Text=" " ToolTip="Delete" />
                               <asp:Button ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" CssClass="rlvBEdit" Text=" " ToolTip="Edit" />
                           </td>
                           <td>
                               <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
                           </td>
                           <td>
                               <asp:Label ID="messageLabel" runat="server" Text='<%# Eval("message") %>' />
                           </td>
                           <td>
                               <asp:CheckBox ID="hasBeenBroadcastCheckBox" runat="server" Checked='<%# Eval("hasBeenBroadcast") %>' Enabled="false" />
                           </td>
                           <td>
                               <asp:Label ID="createdDateLabel" runat="server" Text='<%# Eval("createdDate") %>' />
                           </td>
                           <td>
                               <asp:Label ID="msgIDLabel" runat="server" Text='<%# Eval("msgID") %>' />
                           </td>
                       </tr>
                   </AlternatingItemTemplate>
                   <EditItemTemplate>
                       <tr class="rlvIEdit">
                           <td colspan="6">
                               <table cellspacing="0" class="rlvEditTable">
                                   <tr>
                                       <td>
                                           <asp:Label ID="titleLabel2" runat="server" AssociatedControlID="titleTextBox" Text="title"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:TextBox ID="titleTextBox" runat="server" CssClass="rlvInput" Text='<%# Bind("title") %>' />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           <asp:Label ID="messageLabel2" runat="server" AssociatedControlID="messageTextBox" Text="message"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:TextBox ID="messageTextBox" runat="server" CssClass="rlvInput" Text='<%# Bind("message") %>' />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           <asp:Label ID="hasBeenBroadcastLabel2" runat="server" AssociatedControlID="hasBeenBroadcastCheckBox" Text="hasBeenBroadcast"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:CheckBox ID="hasBeenBroadcastCheckBox" runat="server" Checked='<%# Bind("hasBeenBroadcast") %>' />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           <asp:Label ID="createdDateLabel2" runat="server" AssociatedControlID="createdDateTextBox" Text="createdDate"></asp:Label>
                                       </td>
                                       <td>
                                           <telerik:RadDateTimePicker ID="createdDateTextBox" runat="server" DbSelectedDate='<%# Bind("createdDate") %>' MinDate="<%#new DateTime(1900, 1, 1) %>" SharedCalendarID='<%# Container.OwnerListView.FindControl("rlvSharedCalendar").UniqueID %>' SharedTimeViewID='<%# Container.OwnerListView.FindControl("rlvSharedTimeView").UniqueID %>' Skin="<%#Container.OwnerListView.Skin %>" />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           <asp:Label ID="msgIDLabel2" runat="server" Text="msgID"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:Label ID="msgIDLabel1" runat="server" Text='<%# Eval("msgID") %>' />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td colspan="2">
                                           <asp:Button ID="UpdateButton" runat="server" CommandName="Update" CssClass="rlvBUpdate" Text=" " ToolTip="Update" />
                                           <asp:Button ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel" CssClass="rlvBCancel" Text=" " ToolTip="Cancel" />
                                       </td>
                                   </tr>
                               </table>
                           </td>
                       </tr>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                       <tr class="rlvIEdit">
                           <td colspan="6">
                               <table cellspacing="0" class="rlvEditTable">
                                   <tr>
                                       <td>
                                           <asp:Label ID="titleLabel2" runat="server" AssociatedControlID="titleTextBox" Text="title"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:TextBox ID="titleTextBox" runat="server" CssClass="rlvInput" Text='<%# Bind("title") %>' />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           <asp:Label ID="messageLabel2" runat="server" AssociatedControlID="messageTextBox" Text="message"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:TextBox ID="messageTextBox" runat="server" CssClass="rlvInput" Text='<%# Bind("message") %>' />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           <asp:Label ID="hasBeenBroadcastLabel2" runat="server" AssociatedControlID="hasBeenBroadcastCheckBox" Text="hasBeenBroadcast"></asp:Label>
                                       </td>
                                       <td>
                                           <asp:CheckBox ID="hasBeenBroadcastCheckBox" runat="server" Checked='<%# Bind("hasBeenBroadcast") %>' />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           <asp:Label ID="createdDateLabel2" runat="server" AssociatedControlID="createdDateTextBox" Text="createdDate"></asp:Label>
                                       </td>
                                       <td>
                                           <telerik:RadDateTimePicker ID="createdDateTextBox" runat="server" DbSelectedDate='<%# Bind("createdDate") %>' MinDate="<%#new DateTime(1900, 1, 1) %>" SharedCalendarID='<%# Container.OwnerListView.FindControl("rlvSharedCalendar").UniqueID %>' SharedTimeViewID='<%# Container.OwnerListView.FindControl("rlvSharedTimeView").UniqueID %>' Skin="<%#Container.OwnerListView.Skin %>" />
                                       </td>
                                   </tr>
                                   <tr>
                                       <td colspan="2">
                                           <asp:Button ID="PerformInsertButton" runat="server" CommandName="PerformInsert" CssClass="rlvBAdd" Text=" " ToolTip="Insert" />
                                           <asp:Button ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel" CssClass="rlvBCancel" Text=" " ToolTip="Cancel" />
                                       </td>
                                   </tr>
                               </table>
                           </td>
                       </tr>
                   </InsertItemTemplate>
                   <EmptyDataTemplate>
                       <div class="RadListView RadListView_Office2010Blue">
                           <div class="rlvEmpty">
                               There are no items to be displayed.</div>
                       </div>
                   </EmptyDataTemplate>
                   <ValidationSettings EnableModelValidation="False" EnableValidation="False" />
                   <SelectedItemTemplate>
                       <tr class="rlvISel">
                           <td>
                               <asp:Button ID="DeselectButton" runat="server" CausesValidation="False" CommandName="Deselect" CssClass="rlvBSel" Text=" " ToolTip="Deselect" />
                               <asp:Button ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" CssClass="rlvBDel" Text=" " ToolTip="Delete" />
                               <asp:Button ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" CssClass="rlvBEdit" Text=" " ToolTip="Edit" />
                           </td>
                           <td>
                               <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
                           </td>
                           <td>
                               <asp:Label ID="messageLabel" runat="server" Text='<%# Eval("message") %>' />
                           </td>
                           <td>
                               <asp:CheckBox ID="hasBeenBroadcastCheckBox" runat="server" Checked='<%# Eval("hasBeenBroadcast") %>' Enabled="false" />
                           </td>
                           <td>
                               <asp:Label ID="createdDateLabel" runat="server" Text='<%# Eval("createdDate") %>' />
                           </td>
                           <td>
                               <asp:Label ID="msgIDLabel" runat="server" Text='<%# Eval("msgID") %>' />
                           </td>
                       </tr>
                   </SelectedItemTemplate>
               </telerik:RadListView>
           <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NSMCWebConnectionString %>" DeleteCommand="DELETE FROM [ISAdminSecurity] WHERE [msgID] = @msgID" InsertCommand="INSERT INTO [ISAdminSecurity] ([title], [message], [hasBeenBroadcast], [createdDate]) VALUES (@title, @message, @hasBeenBroadcast, @createdDate)" SelectCommand="SELECT [title], [message], [hasBeenBroadcast], [createdDate], [msgID] FROM [ISAdminSecurity] ORDER BY [createdDate]" UpdateCommand="UPDATE [ISAdminSecurity] SET [title] = @title, [message] = @message, [hasBeenBroadcast] = @hasBeenBroadcast, [createdDate] = @createdDate WHERE [msgID] = @msgID">
               <DeleteParameters>
                   <asp:Parameter Name="msgID" Type="Int32" />
               </DeleteParameters>
               <InsertParameters>
                   <asp:Parameter Name="title" Type="String" />
                   <asp:Parameter Name="message" Type="String" />
                   <asp:Parameter Name="hasBeenBroadcast" Type="Boolean" />
                   <asp:Parameter Name="createdDate" Type="DateTime" />
               </InsertParameters>
               <UpdateParameters>
                   <asp:Parameter Name="title" Type="String" />
                   <asp:Parameter Name="message" Type="String" />
                   <asp:Parameter Name="hasBeenBroadcast" Type="Boolean" />
                   <asp:Parameter Name="createdDate" Type="DateTime" />
                   <asp:Parameter Name="msgID" Type="Int32" />
               </UpdateParameters>
           </asp:SqlDataSource>
       </div>
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 07 Oct 2013 Link to this post

    Hi Panagiotis,

    I have examined your code and I was not able to find on what event you are calling the "closePopupModality" function that should fire the AJAX request and initiate an update for RadListView.

    I may suggest that you handle the RadWindow "OnClientClose" event and fire the AJAX request there. Please have in mind that in order for the RadAjaxManager to update the RadListView, an AJAX request must be fired through the RadAjaxManager, so please try to debug your project and ensure that you are firing that request.

    About your second question, please note that there are no default insert/edit templates for the RadListView control and you will have to set the templates manually.

    Hope that helps.

     

    Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top