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

Client Event OnCommand?

4 Answers 165 Views
ListView
This is a migrated thread and some comments may be shown as answers.
James Daresta
Top achievements
Rank 1
James Daresta asked on 01 Jun 2010, 08:56 PM
I have a RadListView with edit and delete buttons in the template. What I want is that when one clicks edit that the page does a post back. If the delete is clicked I want to perform a ajax to delete the item and rebind the templete. I have tried different ways to achieve this. The biggest problem is that unlike the RadGrid there is no client OnCommand for me to inspect the commands for postback. If I had this I could cancel the ajax call and force a postback for the edit. The closest I have gotten is with the code below, but unfortunately it seems that depending on the order of the settings of the ajaxsettings one button will not work or perform the ajax or postback call. Any suggestions would be appreciated it.

This causes the Edit button to not work. despite it being not set for ajax.

                <telerik:RadListView ID="rlvCustomerProfile_Contacts" runat="server" 
                    ItemPlaceholderID="ContactsContainer" 
                    OnNeedDataSource="rlvCustomerProfile_Contacts_NeedDataSource" 
                    OnItemDataBound="rlvCustomerProfile_Contacts_ItemDataBound">  
                    <LayoutTemplate> 
                        <asp:PlaceHolder ID="ContactsContainer" runat="server"></asp:PlaceHolder> 
                    </LayoutTemplate> 
                    <ItemTemplate> 
                    <table cellspacing="0" cellpadding="4" class="ContentTableBordered TableFullWidth">  
                        <tr> 
                            <td class="ContentTableCellTitleMedium" colspan="8">  
                                <table width="100%" cellpadding="0" cellspacing="0" style="margin:0px 0px 0px 0px;" border="0">  
                                   <tr> 
                                        <td> 
                                            <asp:Label ID="lblLastNameTitle" runat="server" CssClass="LabelBold" Text='<%# Eval("LastName") %>'></asp:Label><asp:Label ID="lblFirstNameTitle" runat="server" CssClass="LabelBold" Text='<%# Eval("FirstName") %>'></asp:Label> 
                                        </td> 
                                        <td align="right">  
                                            <asp:Button ID="btnEdit" runat="server"   
                                                CommandArgument='<%# Eval("CustomerContactId") %>' 
                                                Text="Edit"   
                                                OnClick="btnCustomerProfile_EditContact_Click" 
                                                OnClientClick="alert('test');Master_DoPostBackInstead=true;" /> 
                                            <asp:Button ID="btnDelete" runat="server"   
                                                CommandArgument='<%# Eval("CustomerContactId") %>' 
                                                Text="Delete" 
                                                OnClick="btnCustomerProfile_DeleteContact_Click" 
                                                ValidationGroup="vgContactDelete" />    
                                        </td> 
                                    </tr> 
                                </table> 
 
etc..... 

        protected void rlvCustomerProfile_Contacts_ItemDataBound(object sender, RadListViewItemEventArgs e)  
        {  
            if (e.Item.ItemType == RadListViewItemType.DataItem)  
            {  
                Button delete = e.Item.FindControlRecursive("btnDelete"as Button;  
                if (delete != null) SiteMasterPage.MasterAjaxManager.AjaxSettings.AddAjaxSetting(delete, rlvCustomerProfile_Contacts, SiteMasterPage.MainLoadingPanel);  
            }  
        } 

4 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 02 Jun 2010, 08:54 AM
Hi James,

In order to achieve the desired functionality, you should use RadAjaxManager's OnRequestStart client-side event to conditional disable the ajax. I have attached a small sample page which demonstrates the suggested approach.

All the best,
Rosen
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
James Daresta
Top achievements
Rank 1
answered on 02 Jun 2010, 04:15 PM
Even with your code it took me a while to figure out why it was not working. Your code worked, but still would not. Finally I realized the issue was that I was ajaxifying the actual ListView itself while you were ajaxifying the Panel suroounding it. Once I put a Panel around it then it worked. So my question now is why can I not directly ajaxify the ListView? In the code you sent if I ajaxify the ListViewPanel then the ClientEvents-OnRequestStart fires. If I ajaxify the RadListView1 instead it does not, but the ajax call still operates. Can you explain this further? Thanks.
0
Rosen
Telerik team
answered on 03 Jun 2010, 01:03 PM
Hi James,

The RadListView control should be ajaxified in this way due to how the control is rendered.
As you may know on the server RadAjaxManager will locate the control which should be ajaxified by its ID and wrap it inside an UpdatePanel. However in order RadAjaxManager to track client-side which element is making the ajax call, an element with the same ClientID should exists.
In the case with RadListView there in no wrapping element with such id, therefore RadAjaxManager is not aware that this or a child element is making an ajax request and the does not raised the client-events. 

Best wishes,
Rosen
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
James Daresta
Top achievements
Rank 1
answered on 03 Jun 2010, 01:51 PM
Thanks that explained quite well for me.
Tags
ListView
Asked by
James Daresta
Top achievements
Rank 1
Answers by
Rosen
Telerik team
James Daresta
Top achievements
Rank 1
Share this question
or