Try our conversational search powered by Generative AI!

Events not firing from controls within the NewsItem control


I did try my best to search through current topics and couldn't find anything, so if this has already been answered, I sincerely apologise!

I have a NewsList control, and within the NewsTemplate element I have a LinkButton with an OnCommand event. I have also tried adding an OnClick event too, just to see whether it was an issue with that specific event, yet I see the same.

The event handlers are set in the code-in-front within the NewsList control tags. They're not created dynamically in the code behind. When the button is clicked, a postback occurs, but the event handler method is not called. There's clearly something I'm doing wrong and if anybody could point me in the right direction I'd appreciate it.

Also, first time on this forum, so hello! :)

May 14, 2013 19:08

Also, please ignore the post title. I'm talking about the NewsList control, not NewsItem. It's been a long day...

May 14, 2013 19:10

Could you post the markup you're using?

Here is a simple example of a working Newslist control:


<EPiServer:NewsList runat="server" PageLink="<%# CurrentPage.PageLink %>"> <NewsTemplate> <asp:LinkButton runat="server" ID="btnLink" Text='<%# DataBinder.Eval(Container.DataItem, "PageName") %>' OnCommand="Button_Click" /> </NewsTemplate> </EPiServer:NewsList>



protected void Button_Click(object sender, CommandEventArgs e)
   string foo = ((LinkButton) sender).Text;


May 14, 2013 22:25

Hi Arild, thanks for answering. Markup is as follows (... = code I've removed for sake of verbosity):


<EPiServer:NewsList  runat="server" ID="MyList">
<asp:LinkButton ID="btnMyButton" CssClass="myCssClass" runat="server" CommandName="MyButton" 
                            CommandArgument="<%# Container.CurrentPage.PageLink%>" OnCommand="btn_Click">
                              <asp:Literal ID="litMy" runat="server" Text="<% # Container.CurrentPage.GetTxt()%>"></asp:Literal>


Code behind:

protected void btn_Click(object sender, CommandEventArgs e)

May 15, 2013 10:44

Where do you bind data to your Newslist? This is normally done either in the markup (like I showed with PageLink="<%# CurrentPage.PageLink %>") or in codebehind (e.g. MyList.PageLink = CurrentPage.PageLink; MyList.DataBind();)

Btw I just copied and tried your code and it works (both with databinding in markup and in codebehind) - the btn_click event is firing.

Do you have AutoEventWireup="true" in your Page directive?

Edited, May 15, 2013 10:53

Hi Arild,

Thanks for responding.

The code appears to be bound in a hybrid way - there are elements in the code-in-front as you just described and there's a databind going on in the code behind too. AutoEventWireup is true in my Page directive.

May 15, 2013 11:54

Just to add, I added a LinkButton with that OnCommand outside of the NewsList tags and that works fine. So I presume it must be something to do with the DataBind that, for some reason, is removing those event handlers that are set in the code-in-front?

May 15, 2013 12:27

Yes, seems like it's related to databinding. Is the NewsList control listing the pages? Could you post more of the code/markup where databinding occurs?

May 15, 2013 12:40

Hi Arild, I've worked it out. The code beforehand was databinding within the PreRender, which appears to be far too late along the execution line. Placing it in OnInit works a treat. Thanks so much for your time. :)

May 15, 2013 12:58
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.