+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Event not firing in linkbutton inside datarepeater

Event not firing in linkbutton inside datarepeater

8 posts, 0 answered
  1. KPNQWEST ITALIA SPA
    KPNQWEST ITALIA SPA avatar
    6 posts
    Registered:
    20 Oct 2010
    16 Feb 2011
    Link to this post
    Hi, I am developing a custom control inside a plugin.
    This control has a DataRepeater and each element in the repeater has a LinkButton that must do something in the click event.
    The Repeater's data is binded inside the click event of a serch button.

    Here's an example of the code:

    01.public class TicketList: CompositeControl
    02.{
    03.    Manager manager = new Manager();
    04.    private TicketListContainer container;     
    05.     
    06.    .........
    07.     
    08.    protected override void CreateChildControls()
    09.    {
    10.        container = new TicketListContainer(this);
    11.        LayoutTemplate.InstantiateIn(container);
    12.        Controls.Add(container);
    13. 
    14.        container.SearchButton.Click += new ImageClickEventHandler(SearchButton_Click);
    15.    }
    16.     
    17.    void BindDataToRepeater()
    18.    {
    19.        container.Repeater.ItemCreated += new RepeaterItemEventHandler(RepeaterList_ItemCreated);
    20.        container.Repeater.DataSource = manager.GetData();
    21.        container.Repeater.DataBind();
    22.    }
    23. 
    24.    void RepeaterList_ItemCreated(object sender, RepeaterItemEventArgs e)
    25.    {
    26.        LinkButton linkButton = (LinkButton)Utilities.FindControlRecursive(Container, "TheLinkButton");
    27.        linkButton.Click += (s, ev) => linkButton_Click(linkButton, e, item);
    28.    }
    29.     
    30.    void linkButton_Click(object seder, EventArgs e, KQITicket ticket)
    31.    {
    32.        HttpContext.Current.Response.Redirect("Default.aspx");
    33.    }
    34. 
    35.    void SearchButton_Click(object sender, ImageClickEventArgs e)
    36.    {
    37.        BindDataToRepeater();
    38.    }
    39. 
    40.    .........
    41. 
    42.    private class TicketListContainer : GenericContainer<TicketList>
    43.    {
    44.        public TicketListContainer(TicketList owner)
    45.            : base(owner)
    46.        {
    47. 
    48.        }
    49.         
    50.        Repeater _repeaterList;
    51.        ImageButton _searchbutton;
    52. 
    53.        public Repeater Repeater
    54.        {
    55.            get
    56.            {
    57.                if (_repeaterList == null)
    58.                    _repeaterList = FindRequiredControl<Repeater>("TicketListRepeater");
    59.                return _repeaterList;
    60.            }
    61.        }
    62. 
    63.        public ImageButton SearchButton
    64.        {
    65.            get
    66.            {
    67.                if (_searchbutton == null)
    68.                    _searchbutton = FindRequiredControl<ImageButton>("SearchButton");
    69.                return _searchbutton;
    70.            }
    71.        }
    72.    }
    73.}


    I don't understand why the linkButton_Click is not fired.

    Thanks,
    Gianluca.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Feb 2011
    Link to this post
    Hi ,

    Have you tried to use ASP.NET LinkButton or Button control instead of the ImageButton?

    All the best,
    Ivan Dimitrov
    the Telerik team
  3. KPNQWEST ITALIA SPA
    KPNQWEST ITALIA SPA avatar
    6 posts
    Registered:
    20 Oct 2010
    16 Feb 2011
    Link to this post
    Yes, there is no difference.
  4. KPNQWEST ITALIA SPA
    KPNQWEST ITALIA SPA avatar
    6 posts
    Registered:
    20 Oct 2010
    17 Feb 2011
    Link to this post
    Hi,
    is there any news about my problem?
  5. KPNQWEST ITALIA SPA
    KPNQWEST ITALIA SPA avatar
    6 posts
    Registered:
    20 Oct 2010
    18 Feb 2011
    Link to this post
    I guess not...
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Feb 2011
    Link to this post
    Hi ,

    Most probably there is something else on the page that breaks the click event. Somewhere in the template or skipped part of the code do you set PostBackUrl, because in this case the click event will not be fired.


    Regards,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  7. Kyle
    Kyle avatar
    7 posts
    Registered:
    14 Apr 2011
    01 Aug 2011
    Link to this post
    Hi,

    Did you ever find a solution to this problem?
    I have the same issue, a snippet of my code

    protected void SeriesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    		{
    			var button = e.Item.FindControl("uxLinkButton"as LinkButton;
    			var chartDataSelectorSeries = e.Item.DataItem as ChartDataSelectorSeries;
    			if (button != null && chartDataSelectorSeries != null)
    			{
    				button.Click += new EventHandler(ChangeSeries_OnClick);
    				button.CommandArgument = chartDataSelectorSeries.Id;
    				button.Attributes.Add("dam""this");
    			}
    		}
    
    
    ChangeSeries_OnClick never fires. There is nowhere in my code where I am manually setting the postback url.
    Also the Attribute dam=this comes through on all buttons successfully.
    
    cheers
    
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Aug 2011
    Link to this post
    Hello Kyle,

    Could you try to subscribe for the click of the button in an earlier stage of the lifecycle?

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
8 posts, 0 answered