Invoking and Handling Binder Commands

This article provides only sample code that demonstrates invoking and handling commands with GenericCollectionBinder. For detailed explanation please consult Invoking and handling binder item commands article.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Stores.aspx.cs" Inherits="Stores" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sitefinity" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title>Stores with Generic Collection client binder</title>
</head>
<body xmlns:sys="javascript:Sys" xmlns:dataview="javascript:Sys.UI.DataView" sys:activate="*" xmlns:code="http://schemas.microsoft.com/aspnet/code">
    <form id="form1" runat="server">
 
        <asp:ScriptManager ID="scriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Name="MicrosoftAjax.js" Path="~/Sitefinity/Scripts/MicrosoftAjax.js" />
                <asp:ScriptReference ScriptMode="Inherit" Path="~/Sitefinity/Scripts/MicrosoftAjaxTemplates.js" />
                <asp:ScriptReference ScriptMode="Inherit" Path="~/Sitefinity/Scripts/MicrosoftAjaxAdoNet.js" />
            </Scripts>
        </asp:ScriptManager>
 
        <ul id="storesList" runat="server">
        </ul>
 
        <sitefinity:GenericCollectionBinder id="storesBinder" runat="server"
            TargetId="storesList"
            ServiceUrl="~/Sitefinity/Services/Commerce/Stores.svc"
            BindOnLoad="true"
            OnClientItemEditCommand="OnEditCommand"
            OnClientItemDeleteCommand="OnDeleteCommand"
            OnClientItemSelectCommand="OnSelectCommand"
            DataKeyNames="Id"
            DataMembers="Name, Id">
            <Containers>
                <sitefinity:BinderContainer ID="BinderContainer1" runat="server" RenderContainer="false" TemplateHolderTag="UL">
                    <li>
                        <a sys:href="javascript:void(0);" class="selectCommand">{{Name}}</a>
                        <input type="button" value="Edit" class="editCommand" />
                        <input type="button" value="Delete" class="deleteCommand" />
                    </li>
                </sitefinity:BinderContainer>
            </Containers>
        </sitefinity:GenericCollectionBinder>
 
        <script type="text/javascript">
 
            function OnEditCommand(sender, commandArgs) {
                alert(commandArgs.get_itemIndex());
            }
 
            function OnDeleteCommand(sender, commandArgs) {
                alert(commandArgs.get_itemIndex());
            }
 
            function OnSelectCommand(sender, commandArgs) {
                alert(commandArgs.get_itemIndex());
            }   
 
        </script>
 
      
</body>
</html>
 Note

Binder setup:

If you are developing inside of the Sitefinity admin area, it is not necessary to declare ScriptManager control or add anything to the body element, since all this has been implemented on the base Sitefinity admin page.


Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK