Determine which link was clicked inside RadRotator

3 posts, 1 answers
  1. Ronnie
    Ronnie avatar
    23 posts
    Member since:
    Apr 2008

    Posted 09 Feb 2012 Link to this post

    I have a RadRotator with 2 different LinkButtons inside the template.  Each LinkButton has a command argument that is pulled from the database.  What is the easiest way to determine which LinkButton was clicked in the Rotator_ItemClick event?  The problem that I am having is that I can't determine which LinkButton was clicked so that I can execute specific server side code.  

    <telerik:RadRotator ID="RadRotator1" runat="server"
        DataSourceID="dsProducts" RotatorType="CoverFlowButtons" Skin="Forest" Width="625px"
        Height="350px" ItemHeight="350px" ItemWidth="551px" PauseOnMouseOver="true"
            BorderStyle="None">
        <ItemTemplate>
            <asp:LinkButton ID="lnkAddTestimonial" runat="server" CommandName="AddTestimonial"
            CommandArgument='<%# Eval("ProductID") %>'>Add Review</asp:LinkButton>
            <asp:LinkButton ID="lnkViewTestimonials" runat="server" CommandName="ViewTestimonials"
            CommandArgument='<%# Eval("ProductID") %>'>Read Reviews</asp:LinkButton>
        </ItemTemplate>
    </telerik:RadRotator>
  2. Answer
    Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 13 Feb 2012 Link to this post

    Hello Ronnie,

    You should create a separate event handler for the two LinkButtons. So you create a single event handler called Testimonial_Command and attach it to both of the buttons. Like so:

    ASPX:
    <telerik:RadRotator ID="RadRotator1" runat="server"
        DataSourceID="dsProducts" RotatorType="CoverFlowButtons" Skin="Forest" Width="625px"
        Height="350px" ItemHeight="350px" ItemWidth="551px" PauseOnMouseOver="true"
            BorderStyle="None">
        <ItemTemplate>
            <asp:LinkButton ID="lnkAddTestimonial" runat="server" CommandName="AddTestimonial"
            CommandArgument='<%# Eval("ProductID") %>' OnCommand="Testimonial_Command">Add Review</asp:LinkButton>
            <asp:LinkButton ID="lnkViewTestimonials" runat="server" CommandName="ViewTestimonials"
            CommandArgument='<%# Eval("ProductID") %>' OnCommand="Testimonial_Command">Read Reviews</asp:LinkButton>
        </ItemTemplate>
    </telerik:RadRotator>

    Code:

    protected void Testimonial_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "AddTestimonial")
        {
            // do this
        }
        else if (e.CommandName == "ViewTestimonial")
        {
            // do this instead
        }
    }

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ronnie
    Ronnie avatar
    23 posts
    Member since:
    Apr 2008

    Posted 13 Feb 2012 Link to this post

    That is perfect, exactly what I was looking to do.  Thanks so much.
Back to Top