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

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

3 Answers 38 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Majid Darab
Top achievements
Rank 1
Majid Darab asked on 15 May 2011, 09:30 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 16 May 2011, 09:54 AM
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.
0
Robert
Top achievements
Rank 1
answered on 08 Mar 2013, 06:51 PM
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>
0
Nencho
Telerik team
answered on 13 Mar 2013, 01:16 PM
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.
Tags
ListBox
Asked by
Majid Darab
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or