How Recognize The CammandName Of A LinkButton Inside An ItemTemplate Of A RadListBox

4 posts, 1 answers
  1. Majid Darab
    Majid Darab avatar
    110 posts
    Member since:
    Sep 2012

    Posted 15 May 2011 Link to this post

    hi my dear friends :
    i added an itemtemplate to my radlistbox and also added 1 label and 2 linkbutton in it ...
    my radlistbox is like below :
    <telerik:RadListBox ID="RadlbOfImageGroup" runat="server" DataKeyField="ID" DataSortField="Title"
        DataSourceID="sdsImagesGroup" DataTextField="Title" DataValueField="ID" Skin="BlackByMe"
        EnableEmbeddedSkins="False" Width="260px" Height="365px" EmptyMessage="no rec!"
        AutoPostBack="True" OnSelectedIndexChanged="RadlbOfImageGroup_SelectedIndexChanged"
        CausesValidation="False">
        <ItemTemplate>
            <table style="width: 100%;">
                <tr style="width: 100%;">
                    <td style="width: 64%;">
                        <asp:Label ID="lblTitleOfIG" runat="server" CssClass="lbl_ListBox_IG_Title" Text='<%# Eval("Title") %>'></asp:Label>
                    </td>
                    <td style="width: 18%; text-align: center;">
                        <asp:LinkButton ID="lbEditIG" runat="server" CausesValidation="False" CommandName="Edit"
                            CssClass="lb_ListBox_IG" OnClick="lbEditIG_Click">Edit</asp:LinkButton>
                    </td>
                    <td style="width: 18%; text-align: center;">
                        <asp:LinkButton ID="lbDeleteIG" runat="server" CausesValidation="False" CommandName="Delete"
                            CssClass="lb_ListBox_IG" OnClick="lbDeleteIG_Click">Delete</asp:LinkButton>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </telerik:RadListBox>

    My Problem Is how can i check the CommandName of LinkButtons in code behind when i click on them?
    (we do n't have access to these LinkButtons In CodeBehind)

    thanks for your attention
    best regards
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 May 2011 Link to this post

    Hello Majid,

    One approach is to access the LinkButton using the default argument Sender. Here is a sample code.
    C#:
    protected void lbDeleteIG_Click(object sender, EventArgs e)
       {
           LinkButton btn = sender as LinkButton;
           if (btn.CommandName=="Delete")
           {
               Response.Write("Deleted");
           }
       }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert
    Robert avatar
    23 posts
    Member since:
    Feb 2009

    Posted 08 Mar 2013 Link to this post

    I'm having a related problem.

    I have a RadListBox inside an RadAjaxPanel. When I add an ImageButton to the ItemTemplate for the RadListBox and and then click that button, my page throws the following exception:

    Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format.

    Debugging this I've found that it's not my code throwing the exception. Even having a completely empty event handler results in the same problem. Here is the stack trace that I see:

    >   Galen.MCF.Web.UI.DLL!MyCompany.MyPage.OnError(System.EventArgs e) Line 450  C#
        System.Web.dll!System.Web.UI.Page.HandleError(System.Exception e) + 0x55 bytes 
        System.Web.dll!System.Web.UI.Page.ProcessRequestMain(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) + 0x1a79 bytes 
        System.Web.dll!System.Web.UI.Page.ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) + 0x84 bytes   
        System.Web.dll!System.Web.UI.Page.ProcessRequest() + 0x51 bytes
        System.Web.dll!System.Web.UI.Page.ProcessRequestWithNoAssert(System.Web.HttpContext context) + 0x16 bytes  
        System.Web.dll!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext context) + 0x32 bytes  
        App_Web_fncgkc2z.dll!ASP.mypage_aspx.ProcessRequest(System.Web.HttpContext context) + 0x33 bytes    C#

    The exception's stack trace is:

    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
    at System.Web.UI.WebControls.ImageButton.LoadPostData(String postDataKey, NameValueCollection postCollection)
    at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection)
    at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


    The markup looks like:
    <telerik:RadAjaxPanel ID="rapItemSelector" runat="server" EnableAJAX="true">
        <telerik:RadListBox ID="lstFavoriteItems" runat="server" Width="100%"
                AutoPostBack="True" OnSelectedIndexChanged="SelectedItemChanged"
                DataKeyField="Id" DataValueField="DisplayName" RegisterWithScriptManager="true">
            <ItemTemplate>
                <%# DataBinder.Eval(Container, "DataItem.DisplayName") %>
                <asp:ImageButton ID="btnAddFavorite" runat="server"
                        ImageUrl="~/Images/fav_gray.gif"
                        CausesValidation="False"
                        CommandName="Test"
                        CommandArgument="Test"
                        OnClick="AddFavoriteClicked" />
            </ItemTemplate>
        </telerik:RadListBox>
    </telerik:RadAjaxPanel>
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 13 Mar 2013 Link to this post

    Hello Robert,

    I have inspected the provided snippet of code and tested it at my side, but I was unable to replicate the faced issue. Here's a video, demonstrating the behavior at my end. I would like to ask you to submit a support ticket along with a runnable sample attached demonstrating the faced exception, in order to investigate the issue further.

    All the best,
    Nencho
    the Telerik team
    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 their blog feed now.
Back to Top